Jump to content

PHP array.. checkboxes and an if statement ...easy?


ben_johnson1991

Recommended Posts

Hey guys,

this really should be an easy one, but i can't solve it.

Basically i've got a list of checkboxes, the list is of catalogues from mysql db, with checkbox dedicated to it.

I also have a 'linking' table for the product and catalogues which i used mysql_fetch_array to get the catalogue Id's from that 1 product.

 

then i tried to write if($catalogueID == $catalogueIdFromLinkTable){$checkd = 'CHECKED';}else{$checked='';}

this ran in the while loop for getting the catalogues,

this if statement is supposed to basically check all the catalogues already listed to this product.

 

But obviously this doesnt work because if in the while loop from getting the id's from the link table there is more than 1 id, $catalogueIdFromLinkTable becomes eg"1,3,6" which isn't going to be an id of a catalogue

 

Hopefully this makes a bit of sense and it shouldn't be hard, just one of them brain dead days.

 

Any help'll be awesome!

Cheers,

Ben.

Assuming $catalogueIdFromLinkTable is either a number or a comma separated list of numbers, then:

$ids = explode(',', $catalogueIdFromLinkTable);

if(in_array($catalogueID, $ids)) {
   $checkd = 'CHECKED';
} else {
   $checked='';
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.