kapz22 Posted March 3, 2010 Share Posted March 3, 2010 Hi all, i am having issues with ticking a checkbox if that value exists in the database. Basically i have a form containing about 20 check boxes. when you tick them, the value is inserted into the database and the page reloads. When the page relaods, i want the check boxes ticked, only if those value exists in the database. i know that that "checked" has to be inserted inside the input parameters. i have the follwing code: <?php while ($row = mysql_fetch_assoc($resul)) { ?> <input type="checkbox" name="checkbox[]" value="<?php echo $row["id"]; ?>" <?php echo $checked; ?> /> <?php echo $row["name"]; ?><br /> <?php } ?> How do i get these boxes ticked, it the id exists in the database? Please advise me on what i need to do. Thanks. Quote Link to comment Share on other sites More sharing options...
schilly Posted March 4, 2010 Share Posted March 4, 2010 <input type="checkbox" name="checkbox[]" value="<?php echo $row["id"]; ?>" <?php echo ($row['checkbox_value'] == 1) ? "CHECKED='CHECKED'" : ''; ?> /> I'm sure what your set value is for these checkboxes but I usually use 1. Basically check the checkbox value against whatever your set value is (1 in this case). 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.