Page 1 of 1

Auto Checking a Check box from a Database selection

Posted: Wed Nov 26, 2003 10:08 pm
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

Posted: Thu Nov 27, 2003 3:54 pm
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?

Posted: Thu Nov 27, 2003 4:08 pm
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.