Forum Moderators: coopster

Message Too Old, No Replies

Multiple Filters.or not.

         

inveni0

2:54 am on Jan 26, 2006 (gmt 0)

10+ Year Member



I have a database set up where cities and states are stored. I have a query that takes a URL variable for the state and displays the corresponding rows for the city column. The user can then click the city column, and it will display another page that filters by city and state...BUT:

I want a link on that city page that says SHOW ALL. How do I adjust the final page so that it will show all city rows if no city variable is passed in the URL?

drogyn

10:45 am on Jan 26, 2006 (gmt 0)

10+ Year Member



I suppose your query basically looks something like

SELECT columns FROM tables WHERE statename="$statevar" AND cityname="$pagevar"

Now you could make a script like this:
$query = "SELECT columns FROM tables WHERE TRUE ";
if (!empty($_GET['statevar'])) $query .= "AND state='" . $statevar . '" ';
if (!empty($_GET['cityvar'])) $query .= "AND city='" . $cityvar . '" ';

This way, you normally will only call the full query, but if the page comes with a state or city variable, the query is altered.

Hope it helps. I can be more specific if you give the table information.

--Drogyn