问题描述
谁能帮助我如何在一次提交中提交多行?
此调查表将显示一组源自桌面技能的技能.教师必须在复选框中检查学生的技能并点击提交.
一个学生可以拥有多个技能.如果他有3个技能,那么一旦老师点击提交按钮,发送到数据库的数据将是3行.(表学生技能)
<cfoutput query="skill"><tr><td>#skill.skillname#</td><td align="center">:</td><td><input type="checkbox" name="skillid" value="skillid" checked="checked"></td></tr></cf输出>
餐桌技巧
+---------+------------+|技能 |技能名 |+---------+------------+|1 |画 |+---------+------------+|2 |阅读 |+---------+------------+|3 |舞蹈 |+---------+------------+
表学生技能
+----------+----------||学生|技能 |+----------+----------+|001 |1 ||001 |2 ||002 |1 ||002 |2 ||002 |3 |+----------+----------+
另一种插入多条记录的简单方法是 INSERT .. SELECT
.(在发布的链接banyr中也提到了).因为技能 ID 存储在另一个表中,您可以使用 IN
子句对它们进行 SELECT
.然后通过简单的查询将这些值直接插入到您的另一个表 studenSkill
中,无需循环.
INSERT INTO studenSkill ( studenId, SkillId )选择 <cfqueryparam value="#form.studentId#" cfsqltype="cf_sql_integer">, 技能标识来自技能技能 ID 在哪里(<cfqueryparam value="#form.skillId#" cfsqltype="cf_sql_integer" list="true">)
<input type="checkbox" name="skillid" value="skillid" check="checked">
顺便说一句,如果这不是拼写错误,请不要忘记查询列名称周围的 # 符号,即skillid"
<input type="checkbox" name="skillid" value="#skillid#" checked="checked">
can anyone help me on how to submit multiple rows in one submission?
this survey form will display a set of skill that derived from table skill. the teacher will have to check the students skill's in checkboxes and click submit.
a student can have more than one skill. if he has 3 skills, then the data that is sent into database will be in 3 rows once the teacher click the submit button. (table studentskill)
<cfoutput query="skill">
<tr>
<td>#skill.skillname#</td>
<td align="center">:</td>
<td><input type="checkbox" name="skillid" value="skillid" checked="checked"></td>
</tr>
</cfoutput>
table skill
+---------+------------+
| skillid | skillname |
+---------+------------+
| 1 | draw |
+---------+------------+
| 2 | read |
+---------+------------+
| 3 | dance |
+---------+------------+
table studentskill
+----------+----------|
|studentid | skillid |
+----------+----------+
| 001 | 1 |
| 001 | 2 |
| 002 | 1 |
| 002 | 2 |
| 002 | 3 |
+----------+----------+
Another simple approach for inserting multiple records is an INSERT .. SELECT
. (It is also mentioned in the link banyr posted). Because the skill id's are stored in another table, you can use an IN
clause to SELECT
them. Then insert those values directly into your other table studenSkill
with a simple query, no looping.
INSERT INTO studenSkill ( studenId, skillId )
SELECT <cfqueryparam value="#form.studentId#" cfsqltype="cf_sql_integer">
, skillId
FROM skill
WHERE skillId IN
(
<cfqueryparam value="#form.skillId#" cfsqltype="cf_sql_integer" list="true">
)
<input type="checkbox" name="skillid" value="skillid" checked="checked">
BTW, in case that is not a typo, do not forget the # signs around the query column name ie "skillid"
<input type="checkbox" name="skillid" value="#skillid#" checked="checked">
这篇关于冷融合MSSQL:如何在一次提交中插入具有一个唯一 ID 的多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!