By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,301 Members | 1,766 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,301 IT Pros & Developers. It's quick & easy.

Retriew database values to check boxes

100+
P: 250
my php page has 7 check boxes. I stored checked values to database and retrive as binary values. This is the result array
Expand|Select|Wrap|Line Numbers
  1. Array ( [0] => 0 [1] => 1 [2] => 0 [3] => 1 [4] => 0 [5] => 0 [6] => 1 ) 
  2.  
1 means checked. I want to display these results in check boxes. This is my code. But it doesn't work
Expand|Select|Wrap|Line Numbers
  1. <tr><td><input value="1" type="checkbox"  id="1" name="check" <?php if ($array[0]==1) echo "value=checked";?>/>Fasting 6 hours</td>
  2. <td><input value="2" type="checkbox" id="2" name="check" <?php if ($array[1]==1) echo "value=checked";?>/>Off feeds 3 hours</td>
  3. <td><input value="3" type="checkbox" id="3" name="check" <?php if ($array[2]==1) echo "value=checked";?>/>Full bladder</td></tr>
  4.  <tr>    <td><input value="4" type="checkbox" id="4" name="check" <?php if ($array[3]==1) echo "value=checked";?>/>General anesthesia </td>
  5. <td><input value="5" type="checkbox" id="5" name="check" <?php if ($array[4]==1) echo "value=checked";?>/>Sedation</td></tr>
  6. <tr><td><input value="6" type="checkbox" id="6" name="check" <?php if ($array[5]==1) echo "value=checked";?>/>Steroid cover </td>
  7. <td><input value="7" type="checkbox"  id="7" name="check" <?php if ($array[6]==1) echo "value=checked";?>/>Contact Radiologist </td>
  8. </tr>
  9.  
please help me.
Sep 1 '09 #1
Share this Question
Share on Google+
1 Reply


Markus
Expert 5K+
P: 6,050
@ghjk
What exactly doesn't happen? What is supposed to happen? Do you get any errors?

It looks like it *should* work.

Actually, on second glance, you should be printing 'checked="checked"' as this is the correct HTML attribute.

Mark.
Sep 1 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.