dennismonsewicz
Members-
Posts
1,136 -
Joined
-
Last visited
Everything posted by dennismonsewicz
-
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; }
-
i followed everything up to your last statement... please clearify?
-
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?
-
controlling the value of a checkbox using javascript
dennismonsewicz replied to dennismonsewicz's topic in Javascript Help
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; } ?> -
controlling the value of a checkbox using javascript
dennismonsewicz replied to dennismonsewicz's topic in Javascript Help
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' -
controlling the value of a checkbox using javascript
dennismonsewicz replied to dennismonsewicz's topic in Javascript Help
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!'; } ?> -
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; } ?>
-
do you know how I could fix this?
-
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?
-
now its not displaying anything ???
-
use the LIKE command in SQL http://www.techonthenet.com/sql/like.php
-
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>'; } }
-
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?
-
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"
-
mysql_real_escape_string() expects parameter 2 to be resource
dennismonsewicz replied to waynew's topic in PHP Coding Help
WOW java? I feel your pain man! -
if you are wanting this to validate and even look right, in some cases, make note of the correction i fixed in your code
-
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>';
-
bump
-
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?
-
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"'; }
-
can you give me an example?
-
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?
-
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;
-
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;