npsari Posted April 6, 2007 Share Posted April 6, 2007 I have a Combo-box with 100 selections Select Country All countries uk france usa germany etc... How can I adjust that if 'All countries' was selected... The retreive PHP script will display results of all countries This is the current script I have mysql_select_db(database); $q = "SELECT * FROM rent ORDER BY Date DESC LIMIT 10000;"; How can I assign 'All countries' to display results from all countries Link to comment https://forums.phpfreaks.com/topic/45926-adjust-all-countries-to-display-all-results/ Share on other sites More sharing options...
boo_lolly Posted April 6, 2007 Share Posted April 6, 2007 your current query does display all countries. if the user specified a country, it would be something like this: $q = "SELECT * FROM rent WHERE country = '{$_POST['countries']} ORDER BY Date DESC LIMIT 10000;"; Link to comment https://forums.phpfreaks.com/topic/45926-adjust-all-countries-to-display-all-results/#findComment-223104 Share on other sites More sharing options...
npsari Posted April 6, 2007 Author Share Posted April 6, 2007 Yes, I know how to display a certain country But what if the user chosen 'All countries' How can the code dispay results available from all countries Link to comment https://forums.phpfreaks.com/topic/45926-adjust-all-countries-to-display-all-results/#findComment-223107 Share on other sites More sharing options...
AndyB Posted April 6, 2007 Share Posted April 6, 2007 $countries = $_POST['countries']; $q = "SELECT * from rent"; if ($countries!="All countries") { $q.= " WHERE country = '$countries'"; } $q.= " ORDER by Date DESC LIMIT 10000"; Link to comment https://forums.phpfreaks.com/topic/45926-adjust-all-countries-to-display-all-results/#findComment-223128 Share on other sites More sharing options...
boo_lolly Posted April 6, 2007 Share Posted April 6, 2007 did you not read my post??? YOUR CURRENT QUERY ALREADY DISPLAYS ALL COUNTRIES. if you're looking for the code to do it dynamically, here's an example.... read next time.... $sql = "SELECT * FROM rent". ((isset($_POST['countries']) && $_POST['countries'] == 'All Countries') ? ('') : (' WHERE country = '. $_POST[\'countries\'] .' ')) ."ORDER BY Date DESC LIMIT 10000"; Link to comment https://forums.phpfreaks.com/topic/45926-adjust-all-countries-to-display-all-results/#findComment-223134 Share on other sites More sharing options...
npsari Posted April 6, 2007 Author Share Posted April 6, 2007 Hey guys, thanks much Andy B Your code worked What if I have two comboBoxes One is Countries And other is Rooms How will the code be? Is that right... $countries = $_POST['countries']; $q = "SELECT * from rent"; if ($countries!="All countries") { $q.= " WHERE country = '$countries'"; $Rooms = $_POST['Rooms']; $q = "SELECT * from rent"; if ($Rooms!="All") { $q.= " WHERE Rooms = '$Rooms'"; } $q.= " ORDER by Date DESC LIMIT 10000"; Link to comment https://forums.phpfreaks.com/topic/45926-adjust-all-countries-to-display-all-results/#findComment-223161 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.