Shoutbox

MySQL + Checkboxes - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: MySQL + Checkboxes (/showthread.php?tid=90305)

MySQL + Checkboxes by Eddie on 04-22-2009 at 11:21 AM

After a few google searches, i decided this would be the best place to ask. I have 7 fields in my MySQL database table, one for each day of the week.

I have a form with a checkbox for each field, if checked it adds a "1" to the field.

When it comes to an "update" page, im not sure how to make the checkboxes ticked on the page if there is a "1" in the field in the MySQL Database. The main reason i am asking for this is because a system im working on includes a "Approval" page where an admin will have to see the days that were checked, does anyone know a simpler way or can provide me a solution to this? :D

I know its probably really easy, but thanks :)


RE: MySQL + Checkboxes by Mnjul on 04-22-2009 at 11:46 AM

If you're using PHP it should look like:

php code:
<input type="checkbox" <?php if($row['field']==1) echo "checked=\"checked\""; ?> />

RE: MySQL + Checkboxes by Jarrod on 04-22-2009 at 11:47 AM

I would suggest using some js to check them when the page is loaded, also depending on the application, you could just use graphics if it's just for display purposes and does not need to changed


RE: MySQL + Checkboxes by Eddie on 04-22-2009 at 11:51 AM

quote:
Originally posted by Mnjul
If you're using PHP it should look like:

php code:
<input type="checkbox" <?php if($row['field']==1) echo "checked=\"checked\""; ?> />

Thats what im after, thanks ;)