Solarpitch Posted November 22, 2008 Share Posted November 22, 2008 Hey guys, I want to have a search on my page that will allow the user to select multiple search terms from a check box list. For example, if they were seaching for a mobile phone and the list was.. NETWORK ------------- O2 Vodafone T Mobile Three Ho can I determine which ones was selected so I can create a query for the database? If only O2 and Three were selected I'd want my query to be something like... SELECT * FROM phones WHERE network = 'o2' || network = 'three' Quote Link to comment https://forums.phpfreaks.com/topic/133784-searching-with-check-boxes/ Share on other sites More sharing options...
Philip Posted November 22, 2008 Share Posted November 22, 2008 <?php // $networks is the array of marked checkboxes, after cleanup of course $var = '\''.explode('\', ', $networks).'\''; $query = "SELECT * FROM `phones` WHERE `network` IN($var)"; // continue query ?> Quote Link to comment https://forums.phpfreaks.com/topic/133784-searching-with-check-boxes/#findComment-696237 Share on other sites More sharing options...
Solarpitch Posted November 22, 2008 Author Share Posted November 22, 2008 I see. Would my array to catch them looking something like... <?php if(isset($_GET['02'])){$networks[] = "o2"} if(isset($_GET['meteor'])){$networks[] = "meteor"} if(isset($_GET['vodafone'])){$networks[] = "vodafone"} ?> something like that anyway? Quote Link to comment https://forums.phpfreaks.com/topic/133784-searching-with-check-boxes/#findComment-696246 Share on other sites More sharing options...
Philip Posted November 22, 2008 Share Posted November 22, 2008 Yup Quote Link to comment https://forums.phpfreaks.com/topic/133784-searching-with-check-boxes/#findComment-696249 Share on other sites More sharing options...
Solarpitch Posted November 22, 2008 Author Share Posted November 22, 2008 I tried it your way and I'm trying it this way but it just seems to keep printing ARRAY. <?php if(isset($_POST['o2'])){$network[] = "o2 = 'Yes' ||";} if(isset($_POST['meteor'])){$network[] = "meteor = 'Yes' ||"; } if(isset($_POST['vodafone'])){$network[] = "vodafone = 'Yes'"; } echo $sql = "SELECT * FROM phones WHERE ".$network.""; ?> Just echoed the sql to test and it prints.. SELECT * FROM phones WHERE Array Quote Link to comment https://forums.phpfreaks.com/topic/133784-searching-with-check-boxes/#findComment-696261 Share on other sites More sharing options...
Philip Posted November 22, 2008 Share Posted November 22, 2008 SELECT * FROM `phones` WHERE `network` IN($network) Quote Link to comment https://forums.phpfreaks.com/topic/133784-searching-with-check-boxes/#findComment-696262 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.