我有复选框和值的表中,如果用户选择,他们选择在称为checkedHW为了简单起见阵列的ID的值的复选框,这是什么代码看起来像:在一列中插入多个值mysql?
$ids = implode(',',arrayofids);
$sql = "insert into table(id, type) values($ids,type);
$db->query($sql);
用于测试回波查询:
"insert into table('id1,id2','type')
我认为,如果通过此查询我环,我可以假设这样做:
"insert into table('id1','type');"
"insert into table('id2','type');"
,但我不è Xactly公司很清楚如何做,任何帮助将是美好:)
其实,我解决了它使用:
for($i=0;$i<count(arrayofids); $i++){
$sql = "insert into table(id,type) values(array[$i], 'type'";
$db->query($sql);}
我希望帮助别人,并感谢你们的帮助!
我想'id'数据类型为int类型。 – diEcho
我刚刚添加了一个int cast,它只为第一个值插入了一行 – bubbles