问题描述
我有一个PHP文件上传功能,它还为用户提供了选项,即
为文件分配多个项目关联。文件的名称,标题,
主要项目等在文件上传后插入到MySQL db
的文档链接表中。二级(和多个)项目也是使用单独的列表框选择
(有两个框 - 一个用于主要的
项目,一个用于任何项目/所有相关项目)需要将辅助框中的选定值插入到联结表中,该联结表反映了新上传文件的ID和辅助项目的
(s) -
a协会本身的主键,即:
assoc_id doc_id proj_id
1 265 5
2 265 3
3 265 1
我会使用foreach语句从选择列表中拉出项目,
但是如何获得新生成的doc_id以便将该值传递给关联表?
?我可以在将数据插入主表的同时为其分配变量吗?该ID是自动递增的,并按如下方式将
插入主表:
$ tool_insert =" INSERT INTO工具值(''''' ,'$ uploadname'',''$ tooltitle'',
''$ tooldesc'',''$ tooltype_id'',''$ toolcat_id'',''$ primeproj_id'' ,''$ location'')" ;;
感谢您的帮助。
Christina
I have a PHP file upload feature that also gives the user the option to
assign more than 1 project association to the file. The file''s name, title,
primary project, etc. is inserted into a document link table in a MySQL db
after the file is uploaded. The secondary (and multiple) project(s) are also
selected using a separate list box (there are 2 boxes - one for the primary
project, and one for any/all associated projects) The selected values from
the secondary box need to be inserted into a junction table that reflects
both the id for the newly uploaded file and the secondary project(s) - with
a primary key for the association itself, i.e,:
assoc_id doc_id proj_id
1 265 5
2 265 3
3 265 1
I would use a foreach statement to pull the projects from the select list,
but how do I get the newly generated doc_id in order to pass that value to
the association table? Can I assign it a variable at the same time I insert
the data into the primary table? The ID is auto-incremented and is inserted
into the primary table as follows:
$tool_insert = "INSERT INTO tools VALUES ('''', ''$uploadedname'', ''$tooltitle'',
''$tooldesc'', ''$tooltype_id'', ''$toolcat_id'', ''$primeproj_id'', ''$location'')";
Thanks for any help.
Christina
推荐答案
这篇关于从上传的文件中获取主键值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!