Jump to content

dennismonsewicz

Members
  • Posts

    1,136
  • Joined

  • Last visited

Everything posted by dennismonsewicz

  1. 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; }
  2. i followed everything up to your last statement... please clearify?
  3. 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?
  4. here is the list of checkboxes: <?php $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 . ' /> <label for="checkboxes[' . $names . ']">' . ucwords(str_replace($numbers, '', $names)) . '</label></div>'; } echo $title; } ?>
  5. here is my modified code with an if statement <?php if(isset($_POST['checkboxes'])) { $var = $_POST['checkboxes']; } else { $var = 0; } if(isset($chkbx)) { foreach($chkbx as $key=>$val) { $data_name .= $key . "=" . $var . ","; } $trimmedvar = trim($data_name, ","); $qry = mysql_query("UPDATE has_had_projects SET project = '$project_name', $trimmedvar WHERE project = '$project_name'")or die(mysql_error()); echo 'Testing chkbxs works!'; } ?> Its not working! I get the following error msg Unknown column 'Array' in 'field list'
  6. well the reason I was wondering is because when a user decides they want to edit an entry they receive a screen where it has the data displayed from the DB in front of them. A piece of the editable data is a checklist (where in the DB a 1 == checked; 0 == unchecked) I need it when they click on an item that is checked it will return a zero and update the database when they click the submit button. <?php if($chkbx) { foreach($chkbx as $key=>$val) { $data_name .= $key . "=" . $val . ","; } $trimmedvar = trim($data_name, ","); $qry = mysql_query("UPDATE has_had_projects SET project = '$project_name', $trimmedvar WHERE project = '$project_name'")or die(mysql_error()); echo 'Testing chkbxs works!'; } ?>
  7. Is there anyway to assign the value of a checkbox according to if the user clicks on a checkbox or not? Like if a user clicks on the checkbox then its value will equal 1 if it is unchecked then it will equal 0
  8. AWESOME! It works! Man I have been dealing with this code for three days now and it has been rattling my brain! Thanks! Working Code: <?php $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 . ' /> <label for="checkboxes[' . $names . ']">' . ucwords(str_replace($numbers, '', $names)) . '</label></div>'; } echo $title; } ?>
  9. Code: <?php $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); foreach($row as $k=>$val) { $chk = $val>0?'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 . ' /> <label for="checkboxes[' . $names . ']">' . ucwords(str_replace($numbers, '', $names)) . '</label></div>'; } echo $title; }?> I am writing out the sql column names with this code. The foreach statement is checking if the values of the columns is > 0 and if so set $chk var to checked="checked" but nothing happens when I run the code. Well The names are printed along with the checkboxes but its not checking to see if $val is > 0. Any ideas on how to get this running?
  10. use the LIKE command in SQL http://www.techonthenet.com/sql/like.php
  11. it works like a charm and actually you left off a bracket. Now here is one more thing! The $k is displaying the mysql table column names and I need it to not display the first two... anyway of doing that with your code? update code: $checkbox_qry = mysql_query("SELECT * FROM has_had_projects WHERE project = '" . $results->project . "'")or die(mysql_error()); while($row = mysql_fetch_assoc($checkbox_qry)) { foreach ($row as $k=>$val) { $chk = $val>0?'checked = "checked"':""; $numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 0); echo '<div><input type="checkbox" name="checkboxes[' . $k . ']" class="checkbox" id="' . $k . '" ' . $chk . ' /> <label for="checkboxes[' . $k . '">' . ucwords(str_replace($numbers, '', $k)) . '</label></div>'; } }
  12. ah gotcha sorry i have been working on several things today and that for some reason I was over looking Here is the updated code: $checkbox_qry = mysql_query("SELECT * FROM has_had_projects WHERE project = '" . $results->project . "'")or die(mysql_error()); $field = mysql_num_fields($checkbox_qry); for($i = 2; $i < $field; $i++) { $names = mysql_field_name($checkbox_qry, $i); $numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 0); $title .= '<div><input type="checkbox" name="checkboxes[' . $names . ']" class="checkbox" id="' . $names . '" /> <label for="' . $names . '">' . ucwords(str_replace($numbers, "",$names)) . '</label></div>'; } while($row = mysql_fetch_assoc($checkbox_qry)) { foreach ($row as $k=>$val) { $column .= "Column $k is $val<br>"; $values .= $val; } echo $title; } And yes what determines the check is if $val > 0... how would i accomplish this?
  13. Thank you wayne LOL... wasn't trying to get recognize necessarily just didn't know if you needed this to validate. sorry for sounding "pushy"
  14. if you are wanting this to validate and even look right, in some cases, make note of the correction i fixed in your code
  15. this line will not validate if you run it through a validator: echo '<a href="story.php?id='.$row['story_id'].'"><h3>'.$row['title_of_story'].'</h3></a>'; the correction is this: echo '<h3><a href="story.php?id='.$row['story_id'].'">'.$row['title_of_story'].'</a></h3>';
  16. let me give you all of the code I am working with so you can see what I am trying to do <?php $checkbox_qry = mysql_query("SELECT * FROM has_had_projects WHERE project = '" . $results->project . "'")or die(mysql_error()); while($row = mysql_fetch_assoc($checkbox_qry)) { foreach ($row as $k=>$val) { $column .= "Column $k is $val<br>"; $values .= $val; } } if($values > 0) { $chk = 'checked = "checked"'; } $field = mysql_num_fields($checkbox_qry); for($i = 2; $i < $field; $i++) { $names = mysql_field_name($checkbox_qry, $i); $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 . ' /> <label for="' . $names . '">' . ucwords(str_replace($numbers, "",$names)) . '</label></div>'; } echo $title; ?> I have placed the $chk var in the $title var as to say if it is greater than 0 display checked="checked"... does this help?
  17. what I am trying to do is check the $val var and see if it equals 1 if it does then make the variable $chk = 'checked = "checked"'; Updated code: while($row = mysql_fetch_assoc($checkbox_qry)) { foreach ($row as $k=>$val) { $column .= "Column $k is $val<br>"; $values .= $val; } } if($values > 0) { $chk = 'checked = "checked"'; }
  18. alrighty i will do some more digging about that one.. Heres another one for ya I have this script here: <?php $checkbox_qry = mysql_query("SELECT * FROM has_had_projects WHERE project = '" . $results->project . "'")or die(mysql_error()); while($row = mysql_fetch_assoc($checkbox_qry)) { foreach ($row as $k=>$val) { $column .= "Column $k is $val<br>"; $values .= $val; } } if($values > 0) { $checked = 'checked = "checked"'; } $field = mysql_num_fields($checkbox_qry); for($i = 2; $i < $field; $i++) { $names = mysql_field_name($checkbox_qry, $i); $numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 0); $title .= '<div><input type="checkbox" name="checkboxes[' . $names . ']" class="checkbox" id="' . $names . '" ' . $checked . ' /> <label for="' . $names . '">' . ucwords(str_replace($numbers, "",$names)) . '</label></div>'; } echo $title; When the if($values > 0) runs it checkes all of the boxes instead of the ones with values great than 0 any ideas here?
  19. nope updated code: $count = 0; while($row = mysql_fetch_assoc($checkbox_qry)) { if ($count>0){ foreach ($row as $k=>$val) { $column .= $k . " "; } } $count++; } echo $column;
  20. that didn't work updated code: $row = mysql_fetch_assoc($checkbox_qry); while($row = mysql_fetch_assoc($checkbox_qry)) { foreach ($row as $k=>$val) { $column .= $k . " "; } } echo $column;
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.