ben_johnson1991 Posted July 26, 2010 Share Posted July 26, 2010 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. Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 26, 2010 Share Posted July 26, 2010 if $catalogueIdFromLinkTable becomes eg"1,3,6" then use explode() to separate the various IDs and loop through them as well. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 26, 2010 Share Posted July 26, 2010 if $catalogueIdFromLinkTable becomes eg"1,3,6" then use explode() to separate the various IDs and loop through them as well. Or explode() and use in_array(). Quote Link to comment Share on other sites More sharing options...
ben_johnson1991 Posted July 27, 2010 Author Share Posted July 27, 2010 Could you show me how to stick this in an if() please.. Not too familiar with using arrays Cheers guys. Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted July 27, 2010 Share Posted July 27, 2010 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=''; } Quote Link to comment Share on other sites More sharing options...
Jessica Posted July 27, 2010 Share Posted July 27, 2010 if $catalogueIdFromLinkTable becomes eg"1,3,6" then use explode() to separate the various IDs and loop through them as well. Or explode() and use in_array(). Well duh Quote Link to comment Share on other sites More sharing options...
ben_johnson1991 Posted July 27, 2010 Author Share Posted July 27, 2010 Cheers guys, awesome!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.