Auto Checking a Check box from a Database selection

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gjb79
Forum Commoner
Posts: 96
Joined: Fri Jul 18, 2003 6:35 am
Location: x <-- (DC)
Contact:

Auto Checking a Check box from a Database selection

Post by gjb79 »

I have a dynamic check box element in my page that is generated from items in a mysql database table. I wish it to compair this list to a secondary table, which contains a list of items that have been selected in a previous session, and check mark those items. This way the user can see what settings she had previously and modify them to her needs.

I'm not sure how I can set this up, but I do know there will be an if then statment to compair the first table to the second to determin if there is a match. However since the list is generated dynamically, I'm not sure what I need to know to loop both lists at the same time.

Any ideas?

Thanks
User avatar
gjb79
Forum Commoner
Posts: 96
Joined: Fri Jul 18, 2003 6:35 am
Location: x <-- (DC)
Contact:

Post by gjb79 »

:?: I am having trouble looping two arrays at the same time to do the compairison between the check box and the checked item stored on a seperate sql database. Any Ideas?
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

Code: Select all

$count = count($arrayOfCheckboxes);
for ($i = 0; $i < $count; $i++) &#123;
     if (in_array($arrayOfCheckboxes&#1111;$i], $arrayOfSelectedCheckboxes)) &#123;
          // output check box selected
     &#125; else &#123;
          // output check box
     &#125;
&#125;
Something like that might work.

Basically, it loops through all the checkboxes, and sees if that checkboxes value is in the selected array.
Post Reply