Forum Moderators: coopster
Each of the 25 places may or may not exist in each city.
I want the user to be able to select:
City
Time
Place
City & Place
City & Time & Place
etc...
Also I have only one submit button for the form using method POST.
I have done it with multiple nested if..then and if..elseif checking each condition, but both are slow and seem incredibly inefficient.
You can do it with an array like this:
$cities = array();
$cities['City1'] = 'Place1,Place2,Place5';
$cities['City2'] = 'Place2,Place4,Place6';
etc.
Where each element with the key of each city has a comma delimited list of all the places that exist inside of them.
Then on the form submit you can do:
if (stristr($cities[$_POST['city']], $_POST['place'])) {
/*The place exists in the city */
I hope that explains it.
Sorry for being vague. The user has three options, look for a place, see what places are in a city, or see what places in which cities are open at certain times of the day.
The output for each database entry is:
Name Place, Times Open
Address, City
Map Link
I think what I need is a clever select statement like:
Select * from table where city=$_POST["city"] and city!=$_POST["city"] and/or place=$_POST["place"] and place!=$_POST["place"] and/or time=$_POST["time"] and time!=$_POST["time"]
An example: They select noon-4pm
they get back all the places open noon-4pm in the database.
Then they select a Sam's Grocery and noon-4pm
they get back all the Sam's Grocery's open between noon-4pm.
Or they select Sam's Grocery
they get back all the times they are open and the cities they are in.
accept all POST variables that could be sent then create different SELECT statements depending on what was passed IE (code below not properly formatted its just an example)
if isset $city && !$place {
$query = SELECT * FROM table WHERE city ='$city'
}
elseif isset $city && $place {
$query = SELECT * FROM table WHERE city ='$city' AND place ='$place'
}
elseif etc etc until you cover all possabilities
Then run your output using whichever $query is selected from the above
HTH
Do that for each but replace the city with place, and time.
Then:
if ($where == '') $where = 1;
Then you'll have your $where section of your query.
then do:
$query = "SELECT * FROM table WHERE $where";