简体   繁体   English

更新具有另一个表的ID的表中的记录

[英]Updating records in table with ID from another table

Appreciate any help in advance! 提前感谢您的帮助!

I have a DB with two tables, var table and val table. 我有一个带有两个表的数据库,即var表和val表。

var table var表

varid image vartype 可变图像变型

val table 值表

valid sig winner varid 有效信号获胜者变量

The tables have a 1 to many relationship, meaning there are many val's per var. 这些表具有1对多的关系,这意味着每个var有许多val。

Now with that established, I have a form that asks for the input to populate that database. 现在已经建立了,我有一个表单,要求输入以填充该数据库。

  1. The user can add multiple vals in one go - basically I have the form setup using ajax so when the user completes the fields, it posts to my vale table and then refreshes the content (not the page) using ajax/jquery so the user can enter another val/record. 用户可以一次性添加多个val-基本上我使用ajax设置了表单,因此当用户填写字段时,它将发布到我的vale表中,然后使用ajax / jquery刷新内容(而非页面),以便用户可以输入另一个值/记录。

  2. Once the user has entered all of their vals, the user should add the var record. 用户输入所有值后,用户应添加var记录。 When that var posts to the var table, an varid is automatically assigned and should be associated with the last X number of vals the user entered. 当该变量发布到var表时,将自动分配一个变量,并且应与用户输入的最后X个val关联。

For example 例如

var table var表

varid | varid | image | 图片 vartype 变型
1 | 1 | test.jpg | test.jpg | button 按键

val table 值表

valid | 有效 sig | 信号| winner | 赢家| varid 变数
1 | 1 | true | 真实| true | 真实| 1 1个
2 | 2 | false | 错误 true | 真实| 1 1个
3 | 3 | true | 真实| true | 真实| 1 1个

Anyway, I need help understanding the procedure or theory behind this... In my mind, it goes something like this. 无论如何,我需要帮助来了解其背后的过程或理论...在我看来,它的发展过程是这样的。

  1. My ajax should have a counter to count how many vals the user enters. 我的ajax应该有一个计数器来计算用户输入的val数。
  2. Within the php file that the val form is submitted to, should enter the data and then store the id of the record just entered in an array - pass it back to the page. 在val表单提交到的php文件中,应输入数据,然后将刚输入的记录的ID存储在数组中-将其传递回页面。 each time a record is added, the valid will be stored 每次添加记录,都会存储有效记录
  3. when the user is finished entering vals, it will enter the var - when the php file (separate from val file) is called, it will: 当用户完成输入vals时,它将输入var-调用php文件(与val文件分开)时,它将:
    a. 一种。 insert the var 插入变量
    b. grab the id of the var 抓取var的id
    c. C。 update the records in the val table based on array of ids with the var id 根据具有var id的id数组更新val表中的记录

does this sound right or am I totally in space somewhere? 这听起来正确还是我完全在某个地方的太空中?

any assistance would be greatly appreciated. 任何帮助将不胜感激。

You could create a $_SESSION var and fill it with an array of all the 'valid' using MySQLS mysql_insert_id() function. 您可以使用MySQLS mysql_insert_id()函数创建一个$ _SESSION变量,并用所有“有效”数组填充它。

Then when making the 'var' table insert you can simply update the 'val' table rows that match the 'valid''s stored in the $_SESSION var. 然后,在插入“ var”表时,您可以简单地更新与$ _SESSION var中存储的“ valid”匹配的“ val”表行。

Don't forget to clear the $_SESSION var once that's finished. 完成后,请不要忘记清除$ _SESSION变量

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM