469,358 Members | 1,639 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,358 developers. It's quick & easy.

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 ) 
  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
1 2142
Markus
6,050 Expert 4TB
@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.

Similar topics

2 posts views Thread by anusha.vempati9 | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.