XpertWorlock Posted June 17, 2008 Share Posted June 17, 2008 Hi, I'm trying to have it when the page is loaded up, anything with '1' equals checkbox checked, '0' not checked. Right now I have : $result = mysql_query("SELECT * FROM image"); while($row = mysql_fetch_array($result)) { echo $row['img_brownhair']; echo $row['img_blackhair']; } I'm getting no errors, it works fine, but it displays 1's and 0's. I'm new to php/MySql forms. It would need an update button, but I think I can figure that out :-\ .. well maybe. MySQL version 5.0.45-community Thanks for any help it is greatly appreciated. Mike Quote Link to comment Share on other sites More sharing options...
fenway Posted June 17, 2008 Share Posted June 17, 2008 What does an "image" row look like? Quote Link to comment Share on other sites More sharing options...
Mattyspatty Posted June 17, 2008 Share Posted June 17, 2008 this piece of code will create a checkbox, $checked is either NULL or the word 'checked' which will cause the checkbox to be checked when the page is loaded shouldnt be too difficult for you to alter it. <?php if($row['checked']==1) { $checked = "checked"; } else { $checked = ""; } echo "<input name=\"image[$row['img]\" type=\"checkbox\" value=\"true\" $checked >" ?> Quote Link to comment Share on other sites More sharing options...
XpertWorlock Posted June 17, 2008 Author Share Posted June 17, 2008 What does an "image" row look like? Name img_name Size (Bytes) img_size Type (JPG,GIF) img_type File History img_filehistory Brown Hair img_brownhair Now I have this..... $result = mysql_query("SELECT * FROM image"); while($row = mysql_fetch_array($result)) if($row['checked']==1) { $checked = "checked"; } else { $checked = ""; } echo "<input name=\"image[$row['img_brownhair]\" type=\"checkbox\" value=\"true\" $checked >" and I get an error on the last line (the echo) T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING it works if I do this : I took out the ' in the [img_brownhair] and added a ; at the end of the echo, although if img_brownhair already equalled "1" (checked) it doesn't show up checked. Quote Link to comment Share on other sites More sharing options...
XpertWorlock Posted June 17, 2008 Author Share Posted June 17, 2008 I don't know if it matters enum ='0','1' null = no default =0 Quote Link to comment Share on other sites More sharing options...
fenway Posted June 17, 2008 Share Posted June 17, 2008 while($row = mysql_fetch_array($result)) if($row['checked']==1) { $checked = "checked"; } else { $checked = ""; } echo "<input name=\"image[$row['img_brownhair]\" type=\"checkbox\" value=\"true\" $checked >"[/b] This makes no sense -- you don't have a column called checked; and your life will be much simpler if you use different quoting inside & out. Quote Link to comment Share on other sites More sharing options...
XpertWorlock Posted June 17, 2008 Author Share Posted June 17, 2008 I don't know where I am going wrong, I search and search but most people are using arrays to do their checkboxes, which is okay, if I could figure out how to do it. What I'm looking for by default every image uploaded has no checkboxes checked == 0 one table with multiple rows (or just one if the array method works) and an update button when update is clicked, it updates the database and refreshes the page. All the help I've received is greatly appreciated, I'm trying to learn as much as I can. Thanks Mike Quote Link to comment Share on other sites More sharing options...
fenway Posted June 18, 2008 Share Posted June 18, 2008 Please re-read my previous posts. You're clearly confusing your HTML "rows" with your DB "rows". I have no idea what the checkboxes are for, how they get populated, or where they get saved. Quote Link to comment Share on other sites More sharing options...
XpertWorlock Posted June 20, 2008 Author Share Posted June 20, 2008 So far everything is working like it is supposed to. 1= checked 0=unchecked. if($row['img_brownhair']==1) { $checked = "checked"; } else { $checked = ""; } echo "<input name=\"img_brownhair\" type=\"checkbox\" value=\"true\" $checked >"; My last part to this question is how do I update the database, if it is changed on screen? echo "<input type=submit value=Update>"; that creates the update button. Do I have to change the input name on the checkbox? Quote Link to comment Share on other sites More sharing options...
dannyb785 Posted June 21, 2008 Share Posted June 21, 2008 What does an "image" row look like? Name img_name Size (Bytes) img_size Type (JPG,GIF) img_type File History img_filehistory Brown Hair img_brownhair Now I have this..... $result = mysql_query("SELECT * FROM image"); while($row = mysql_fetch_array($result)) if($row['checked']==1) { $checked = "checked"; } else { $checked = ""; } echo "<input name=\"image[$row['img_brownhair]\" type=\"checkbox\" value=\"true\" $checked >" and I get an error on the last line (the echo) T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING it works if I do this : I took out the ' in the [img_brownhair] and added a ; at the end of the echo, although if img_brownhair already equalled "1" (checked) it doesn't show up checked. Get rid of the first single quote where it says img_brownhair and it should work 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.