Boy I could use some advice. I'm getting lost in the logic. There must be an easier way. I'm puting together an event list site. I have the database up and running. Events posting to the DB fine. My logic trouble is in the Search/query pages. The Search page consists of four mutiple select(dropdown) menus. The filter selections are (year[], month[], event type[], and event size[] (which are columns in the DB) with the word "ALL" as a selection in each menu. Follow?
I have gotten as far as getting a correct result back for one column. The query uses three cases. "ALL" , "SOME" , or "ONE of the selections.
If I start to think of nesting "IF" statements for every combination of 4 sets of "ALL" , "SOME" , or "ONE, I just get the
I know the SWITCH statement might help, but it dosen't seem like it would much. There must be another way of approching this.
Can you do this with IF?:
Code: Select all
$count_month=count($date_filter);
$count_type=count($event_type_filter);
$count_size=count($size_filter);
if ($count_month == 1 and $count_date == 1 and $count_size == 1)
{
reset($date_filter);
reset($event_type_filter);
reset($size_filter);
$date_filter=pos($date_filter);
$event_type_filter=pos($event_type_filter);
$size_filter=pos($size_filter);
}
$ALL="ALL";
echo "$date_filter "." $event_type_filter "." $size_filter "."Anyway... This is my approch,
but I dont think it can work with multiple multiples.
Code: Select all
//This returns events in all months
//date_filter is month filter
$count=count($date_filter);
if ($count==1)
{
reset($date_filter);
$date_filter=pos($date_filter);
}
$ALL="ALL";
if ($date_filter == "$ALL")
{
$query = "SELECT eventnum, date_year, date_month, date_day, event_size, event_type, FROM db";
//This returns multiple months (i.e JAN FEB MAR only)
if ($date_filter!=$ALL)
{
$count = count($date_filter);
}
if ( $count > 1 )
{
$date_filter = implode( "','", $date_filter);
$query = "SELECT eventnum, date_year, date_month, date_day, event_size, event_type,
FROM eventpost WHERE date_month IN ('$date_filter')";
//This returns single (not ALL) selections only
else
{
$query = "SELECT eventnum, date_year, date_month, date_day, event_size, event_type,
FROM eventpost WHERE date_year='$year_filter' AND date_month='$date_filter' AND event_size='$size_filter' AND event_type='$event_type_filter'";I would very much appreicate any advice and would love maybe some sample code from another query page that deals with multiples.
Thanks PHP's ........Virgil