472,123 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,123 software developers and data experts.

Retriew database values to check boxes

250 100+
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 ) 
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>
please help me.
Sep 1 '09 #1
1 2266
6,050 Expert 4TB
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.

Sep 1 '09 #2

Post your reply

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

Similar topics

2 posts views Thread by anusha.vempati9 | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.