dennismonsewicz Posted October 3, 2008 Share Posted October 3, 2008 I have this code: <?php if($chkbx) { foreach($chkbx as $key=>$val) { $newval = $val==1?1:0; $data_name .= $key . "=" . $newval . ","; } $trimmedvar = trim($data_name, ","); $qry = "UPDATE has_had_projects SET project = '$project_name', $trimmedvar WHERE project_id = '$id'"; echo $qry; } ?> This works as far as updating the checkboxes that have been checked but what I can't get working is setting all of the other values to 0 if they are unchecked... any help here? Quote Link to comment Share on other sites More sharing options...
ghqwerty Posted October 3, 2008 Share Posted October 3, 2008 you have no clause if($chkbx){ is like me running up to you and saying if hello an acceptable response from you would be . what thats exactly what php is doing Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted October 3, 2008 Author Share Posted October 3, 2008 i followed everything up to your last statement... please clearify? Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted October 3, 2008 Author Share Posted October 3, 2008 the $chkbx var is set like this $chkbx = $_POST['checkboxes']; The code that is spitting out the checkboxes is this: checkbox_qry = mysql_query("SELECT * FROM has_had_projects WHERE project = '" . $results->project . "'")or die(mysql_error()); $field = mysql_num_fields($checkbox_qry); while($row = mysql_fetch_assoc($checkbox_qry)) { for($i = 2; $i < $field; $i++) { $names = mysql_field_name($checkbox_qry, $i); $chk = $row[$names]==1?'checked="checked"':''; $numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 0); $title .= '<div><input type="checkbox" name="checkboxes[' . $names . ']" class="checkbox" id="' . $names . '" ' . $chk . ' value="1" /> <label for="checkboxes[' . $names . ']">' . ucwords(str_replace($numbers, '', $names)) . '</label></div>'; } echo $title; } Quote Link to comment Share on other sites More sharing options...
ultratek Posted October 3, 2008 Share Posted October 3, 2008 every if statement has to have an else Quote Link to comment Share on other sites More sharing options...
Flames Posted October 3, 2008 Share Posted October 3, 2008 every if statement has to have an else Actually you don't need an else to an if statement. Here is a quick thing i found searching php if statement in firefox http://www.tizag.com/phpT/if.php you can have an if statement which has no else. if(something to check) { something to be done } This will be done no matter what the if statement says Quote Link to comment Share on other sites More sharing options...
Barand Posted October 3, 2008 Share Posted October 3, 2008 Unchecked checkbox values are not posted. Quote Link to comment Share on other sites More sharing options...
waynew Posted October 3, 2008 Share Posted October 3, 2008 Of course you can have an IF statement without an else.....? You could have one million IF statements, lined up one after the other if you wanted. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 3, 2008 Share Posted October 3, 2008 every if statement has to have an else On your planet, maybe Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.