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' 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 ?> 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? 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 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 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) Link to comment https://forums.phpfreaks.com/topic/133784-searching-with-check-boxes/#findComment-696262 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.