我有两个值类似的复选框
<input type="checkbox" name="analysis[]" value="'.$rows['name'].'_'.$rows['cost'].'">
我只想用插入查询循环第一个值(名称)
这是我的代码,可以正常工作,但是每次只插入一条记录。循环不起作用
$allAnalysis = $_REQUEST['analysis'];
foreach($allAnalysis as $analysis)
{
$analysis = explode("_", $analysis);
$analysis_name = $analysis[0];
$analysis_insert = "INSERT INTO analysis (
analysis_id ,
analysis_name
) VALUES (
NULL ,
'".$analysis_name."'
)";
}
答案 0 :(得分:-1)
请在foreach中添加SQL查询。
foreach (...){
....
$analysis_insert = "INSERT INTO analysis (
analysis_id ,
analysis_name
) VALUES (
NULL ,
'".$analysis_name."'
)";
/// add here your query
mysql_query( $analysis_insert);
}