Jump to content

Show all results from mySQL database!


npsari

Recommended Posts

I have a comboBox called Countries

I want if a user selects 'All countries' he gets all results from the database

 

I usedthis code, and it worked...

 

mysql_select_db(database);

$Countries = $_POST['Coutries'];
$q = "SELECT * from table";
if ($Countries!="All countries") {
    $q.= " WHERE Countries = '$Countries'";
}

$q.= " ORDER by Date DESC LIMIT 100";}

 

 

But I have a second combobox which is Town

I want if the user selects all towns, he also gets all results

I did this, but it doesnt work :(

 

 

mysql_select_db(database);

$Countries = $_POST['Coutries'];
$q = "SELECT * from table";
if ($Countries!="All countries") {
    $q.= " WHERE Countries = '$Countries'";
}

$Town = $_POST['Town'];
$q = "SELECT * from table";
if ($Town!="All Towns") {
    $q.= " WHERE Town = '$Town'";
}


$q.= " ORDER by Date DESC LIMIT 100";

 

How can I make it work

Link to comment
https://forums.phpfreaks.com/topic/45995-show-all-results-from-mysql-database/
Share on other sites

You mean like this...

 

 

mysql_select_db(database);

$Countries = $_POST['Coutries'];
$q = "SELECT * from table";
if ($Countries!="All countries") {
    $q.= " WHERE Countries = '$Countries'";
}


$town = % (mysql wildcard) if $_POST['town'] == Alltowns.

$q.= " ORDER by Date DESC LIMIT 100";

 

 

Can you please show me where do I put your part to my code

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.