Jump to content

Adjust "All countries" to display all results


npsari

Recommended Posts

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

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;";

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";

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";

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.