mysql - Php - variable in variable name -


i have form several checkboxes. these boxes have 1 row each in mysql db if checked. now, need have loop build query delete rows not checked. tried 1 below array never populated... appreciated...

$chk_cab_1  = isset($_post['chk_cab_1']) ?: 0; $chk_cab_2  = isset($_post['chk_cab_2']) ?: 0; $chk_cab_3  = isset($_post['chk_cab_3']) ?: 0; $chk_cab_4  = isset($_post['chk_cab_4']) ?: 0; $chk_cab_5  = isset($_post['chk_cab_5']) ?: 0; $chk_cab_6  = isset($_post['chk_cab_6']) ?: 0; $chk_cab_7  = isset($_post['chk_cab_7']) ?: 0; $chk_cab_8  = isset($_post['chk_cab_8']) ?: 0; $chk_cab_9  = isset($_post['chk_cab_9']) ?: 0; $chk_cab_10 = isset($_post['chk_cab_10']) ?: 0; $chk_cab_11 = isset($_post['chk_cab_11']) ?: 0;   $check_cab    = array(); $del_cab_ids  = array(); for($i = 1; $i<=$counter; $i++) {     $check_cab["chk_cab_$i"]     = $chk_cab_$i;     if($check_cab["chk_cab_$i"] == 0) {        $del_cab_ids[] = $i;     } }  $sql = "delete mytable          first_id = $t_key         , second_id in ($del_cab_ids)"; 

i change html, if possible rename checkboxes this:

<input name="chk_cab[0]" type="checkbox" value="1" /> ... <input name="chk_cab[5]" type="checkbox" value="1" /> ... 

and invert query:

$sql = "delete mytable first_id = ?";  if (isset($_post['chk_cab']) {     $ids = join(',', array_map('intval', array_keys($_post['chk_cab'])));      $sql .= " , second_id not in ($ids)"; } 

important: assumes entries matched first_id = <whatever> accounted within [1 .. $counter].


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -