[英]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表。
varid image vartype 可变图像变型
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. 现在已经建立了,我有一个表单,要求输入以填充该数据库。
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刷新内容(而非页面),以便用户可以输入另一个值/记录。
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 例如
varid | varid | image |
图片 vartype
变型
1 | 1 | test.jpg |
test.jpg | button
按键
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. 无论如何,我需要帮助来了解其背后的过程或理论...在我看来,它的发展过程是这样的。
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.