问题
i have checkbox with two values like
<input type="checkbox" name="analysis[]" value="'.$rows['name'].'_'.$rows['cost'].'">
i want loop only the first value (name) with insert query
that is my code , working but it only insert one record every time . loop not working
$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."'
)";
}
回答1:
Please add SQL query inside foreach.
foreach (...){
....
$analysis_insert = "INSERT INTO analysis (
analysis_id ,
analysis_name
) VALUES (
NULL ,
'".$analysis_name."'
)";
/// add here your query
mysql_query( $analysis_insert);
}
来源:https://stackoverflow.com/questions/52323467/how-to-loop-only-first-value-from-checkbox-with-insert-query