How to loop only first value from checkbox with insert query

情到浓时终转凉″ 提交于 2020-02-07 01:27:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!