这种方法很完美,但这是正确的方法吗?
<?
/////////////////add/////////////////////////////////
for ($i=0; $i<count($_POST['newhour_start']); $i++) {
if ($_POST['newhour_start'][$i] !="" && $_POST['newhour_end'][$i] !="" ) {
$inserthour = mysql_query("INSERT INTO hour
(hour_start,hour_end,hour_day) VALUES
('".$_POST['newhour_start'][$i]."','".$_POST['newhour_end'][$i]."','".$_POST['newhour_day'][$i]."')");
}
}
?>
Start:<input name="newhour_start[]" type="text" id="newhour_start" > End: <input name="newhour_end[]" type="text" id="newhour_end" ><input name="newhour_day[]" type="hidden" id="newhour_day" value="Monday" >
Start:<input name="newhour_start[]" type="text" id="newhour_start" > End: <input name="newhour_end[]" type="text" id="newhour_end" ><input name="newhour_day[]" type="hidden" id="newhour_day" value="Monday" >
Start:<input name="newhour_start[]" type="text" id="newhour_start" > End: <input name="newhour_end[]" type="text" id="newhour_end" ><input name="newhour_day[]" type="hidden" id="newhour_day" value="Monday" >
答案 0 :(得分:3)
您可以一次插入多行:
mysql_query("INSERT INTO hour
(hour_start,hour_end,hour_day) VALUES
(1, 2, 3),
(4, 5, 6)
);