简体   繁体   English

插入时如何将这些数据库表链接在一起

[英]How to link these database tables together when inserting

I'm trying to build a checklist/signoff system. 我正在尝试建立清单/签核系统。 Basically, I've got a form that the user fills out, see below. 基本上,我有一个用户填写的表格,请参见下文。 The user is automatically put there based on who is logged in. 用户将根据登录的用户自动放置在此处。

http://i.imgur.com/sTysmyV.jpg http://i.imgur.com/sTysmyV.jpg

Each Checklist is attached to a specific Job number. 每个清单都附有特定的工作编号。 So say a manager wants to look at Job 1000, he'll click it, navigate to "Checklists" and he'll see the checklist below. 因此,假设某位经理想要查看Job 1000,他将单击它,导航到“清单”,然后将在下面看到清单。

http://i.imgur.com/kGqcyZt.jpg http://i.imgur.com/kGqcyZt.jpg

Now, I have an option to select different revisions of a checklist for a job so that managers can look at different revisions. 现在,我可以选择一项工作清单的不同修订,以便经理可以查看不同的修订。

I'm just not sure on how to string everything together. 我只是不确定如何将所有内容串在一起。

I have 2 tables so far. 到目前为止,我有2张桌子。

checklist_component_stock checklist_component_stock

Imgur

and checklist_revision 和checklist_revision

Imgur

I'm not sure how to link everything correctly in the tables so when Rev1 gets pulled up say for Job 1000, it shows the correct rows that have been created for that specific job and revision. 我不确定如何正确地链接表中的所有内容,因此当对Job 1000调用Rev1时,它会显示为该特定作业和修订创建的正确行。

Assuming I'm understanding your question correctly, Each time a checklist is updated, I'm guessing that you're currently updating the existing checklist_component_stock record, and inserting the new revision information into the checklist_revision table..? 假设我正确地理解了您的问题,那么每次更新清单时,我猜测您当前正在更新现有的checklist_component_stock记录,并将新的修订信息插入到checklist_revision表中。

If so, then you need to add a revision field into your checklist_component_stock table, and make this part of the foreign key to the checklist_revision table. 如果是这样,则需要在您的checklist_component_stock表中添加一个revision字段,并将其作为checklist_revision表的外键的一部分。

Then, when a checklist is changed, insert a new record into checklist_component_stock with the new revision number, as well as inserting your new revision information into the checklist_revision table. 然后,当清单更改时, 新记录插入具有新修订版本号的checklist_component_stock ,并将新修订信息插入checklist_revision表中。

Then, when you pull back a specific revision, you'll do something like: 然后,当您撤回特定修订时,您将执行以下操作:

SELECT *
FROM checklist_component_stock a
INNER JOIN checklist_revision b ON a.job_num = b.job_num
                                AND a.revision = b.revision
WHERE a.job_num = xxx
AND a.revision = yyy

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

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