Jump to content

What am I missing here? Help!


TechMistress

Recommended Posts

Hello all!.  I can't seem to get this working right.  Well - it renders right, but something is going wrong.  It's a set of filters for events.  The filter marked "type" (category) works fine - but the ones for "location" and "venue" do nothing. They don't show an error, they just don't function.

 

Any help would be appreciated!

 

This is the code:

$typeQuery = "SELECT DISTINCT eventCategory FROM eventcal_events where userSubmitted = '0' ORDER BY eventCategory";
$typeList = mysql_query($typeQuery) or die(mysql_error());
$numtypes = mysql_num_rows($typeList);

$typeselect = "<select name=\"type\" style=\"width:110px;\">";
if($type == "All"){
   $all = "selected";
   $typefilter = "";
} else {
   if ($type <> "") {
      $typefilter = "AND eventCategory='" . $type . "'";
   }
}

$typeselect .= "<option value=\"All\" " . $all . ">All Categories</option>";
while($typearray = mysql_fetch_array($typeList)){
   if($typearray["eventCategory"] != "") {
      $selected = "";
      if($typearray["eventCategory"] == $type) {
         $selected = "selected";
      }
      $typeselect .= "<option value=\"" . $typearray["eventCategory"] . "\" " . $selected . ">" . substr($typearray["eventCategory"],0,15) . "</option>";
   }
}

$typeselect .= "</select>";
#if($numtypes < 2) {
#   $typeselect = "";
#}

$locationQuery = "SELECT DISTINCT eventLocation FROM eventcal_events where userSubmitted = '0' ORDER BY eventLocation";
$locationList = mysql_query($locationQuery) or die(mysql_error());
$numtypes = mysql_num_rows($locationList);

$locationselect = "<select name=\"location\" style=\"width:110px;\">";
if($location == "All"){
   $all = "selected";
   $locationfilter = "";
} else {
   if ($location <> "") {
      $locationfilter = "AND eventLocation='" . $location . "'";
   }
}

$locationselect .= "<option value=\"All\" " . $all . ">All Locations</option>";
while($locationarray = mysql_fetch_array($locationList)){
   if($locationarray["eventLocation"] != "") {
      $selected = "";
      if($locationarray["eventLocation"] == $location) {
         $selected = "selected";
      }
      $locationselect .= "<option value=\"" . $locationarray["eventLocation"] . "\" " . $selected . ">" . $locationarray["eventLocation"] . "</option>";
   }
}
$locationselect .= "</select>";
#if($numtypes < 2) {
#   $locationselect = "";
#}

$venueQuery = "SELECT DISTINCT eventVenue FROM eventcal_events where userSubmitted = '0' ORDER BY eventVenue";
$venueList = mysql_query($venueQuery) or die(mysql_error());
$numtypes = mysql_num_rows($venueList);

$venueselect = "<select name=\"venue\" style=\"width:110px;\">";
if($venue == "All"){
   $all = "selected";
   $venuefilter = "";
} else {
   if ($venue <> "") {
      $venuefilter = "AND eventVenue='" . $venue . "'";
   }
}
$venueselect .= "<option value=\"All\" " . $all . ">All Venues</option>";

while($venuearray = mysql_fetch_array($venueList)){
   if($venuearray["eventVenue"] != "") {
      $selected = "";
      if($venuearray["eventVenue"] == $venue) {
         $selected = "selected";
      }
      $venueselect .= "<option value=\"" . $venuearray["eventVenue"] . "\" " . $selected . ">" . $venuearray["eventVenue"] . "</option>";
   }
}
$venueselect .= "</select>";
#if($numtypes < 2) {
#   $venueselect = "";
#}

$dow = "";
if ($_GET['dow'] <> "") {
   $dow = $_GET['dow'];
}
if ($_POST['dow'] <> "") {
   $dow = $_POST['dow'];
}
if ($dow == 7) {
   $dow = "";
}

$dayselect = "<select name=\"dow\" style=\"width:110px;\">";
if ($dow == "") {
   $selected = "selected";
} else {
   $selected = "";
}
$dayselect .= "<option value=\"7\" " . $selected . ">All Days</option>";
if ($dow == 1) {
   $selected = "selected";
} else {
   $selected = "";
}
$dayselect .= "<option value=\"1\" " . $selected . ">Monday</option>";
if ($dow == 2) {
   $selected = "selected";
} else {
   $selected = "";
}
$dayselect .= "<option value=\"2\" " . $selected . ">Tuesday</option>";
if ($dow == 3) {
   $selected = "selected";
} else {
   $selected = "";
}
$dayselect .= "<option value=\"3\" " . $selected . ">Wednesday</option>";
if ($dow == 4) {
   $selected = "selected";
} else {
   $selected = "";
}
$dayselect .= "<option value=\"4\" " . $selected . ">Thursday</option>";
if ($dow == 5) {
   $selected = "selected";
} else {
   $selected = "";
}
$dayselect .= "<option value=\"5\" " . $selected . ">Friday</option>";
if ($dow == 6) {
   $selected = "selected";
} else {
   $selected = "";
}
$dayselect .= "<option value=\"6\" " . $selected . ">Saturday</option>";
if ($dow == "0") {
   $selected = "selected";
} else {
   $selected = "";
}
$dayselect .= "<option value=\"0\" " . $selected . ">Sunday</option>";
$dayselect .= "</select>";


if ($dow <> "") {
   $day_where = " and (DATE_FORMAT(eventDate,'%w') = '$dow' or DATE_FORMAT(eventDateEnd,'%w') = '$dow')";
} else {
   $day_where = "";
}

# keyword filter
$keyword = "";
if ($_POST['keyword'] <> "Enter Keyword(s)" and $_POST['keyword'] <> "") {
   $keyword = $_POST['keyword'];
   $keywordfilter = " and (eventTitle like '%$keyword%' or eventDescription like '%$keyword%')";
} else {
   $keyword = "Enter Keyword(s)";
   $keywordfilter = "";
}

$keywordbox = "<input type=text name=keyword id=keyword value='$keyword' class='subnav' size=20px onfocus=\"this.value='';\">";

$countQuery = "select * from eventcal_events where userSubmitted = '0' $wheredate $day_where $typefilter $venuefilter $locationfilter $keywordfilter";
$countList = mysql_query($countQuery) or die(mysql_error());
$record_count = mysql_num_rows($countList);

list($eventsperpage) = mysql_fetch_array(mysql_query("SELECT value FROM eventcal_settings WHERE variable='events_per_page'")) or die(mysql_error());

if($eventsperpage == "All"){
   $limit = "";
   $eventsperpage = $record_count;
} else {
   $limit = "limit  " . $start . ", " . ($eventsperpage + 1);
}

list($sort) = mysql_fetch_array(mysql_query("SELECT value FROM eventcal_settings WHERE variable='sort'"));
if ($sort == "date") {
   $order_it = "eventDate, eventTitle";
} else {
   $order_it = "eventTitle";
}

$eventQuery = "select * from eventcal_events where userSubmitted = '0' $wheredate $day_where $typefilter $venuefilter $locationfilter $keywordfilter order by $order_it " . $limit;
# echo $eventQuery . "<br>";
$eventList = mysql_query($eventQuery) or die(mysql_error());
$row_count = mysql_num_rows($eventList);

if ($record_count > 0) {
   $navigate = "Events " . ($start + 1) . " - ";
   if ($row_count > $eventsperpage) {
      $navigate .= ($start + $eventsperpage);
   } else {
      $navigate .= ($start + $row_count);
   }
   $navigate .= " of " . $record_count;

   if ($start > 0) {
      $navigate = "<a href=?month=$month&year=$year&start=" . ($start - $eventsperpage) . "><   Prev</a>   " . $navigate;
   }
   if (($start + $eventsperpage) < $record_count) {
      $navigate .= "   <a href=?month=$month&year=$year&start=" . ($start + $eventsperpage) . ">Next  ></a>";
   }
} else {
   $navigate = "There are no events to display.";
} 

 

This is the html on the page:

 

# filter settings
$fil_query = "select variable, value from eventcal_settings where variable like 'filter_%'";
$fil_rs = mysql_query($fil_query);
$filters = array();
$col_ct = 0;
while ($fil_row = mysql_fetch_array($fil_rs)) {
   $filters[$fil_row['variable']] = $fil_row['value'];
   if ($fil_row['value'] == "Y") {
      $col_ct++;
   }
}
?>
<table border="0" cellspacing="0" cellpadding="0">
<form name="s2" method="post" action="">
<tr><td colspan="<?=$col_ct ?>" align="right" class="subnav">
<p align="left"><strong>Filter Events by</strong>: </td></tr>
<tr valign="top">
<? if($filters['filter_cat'] == "Y") { ?>
<td align="left" class="subnav"><?=$typeselect ?></td>
<? } ?>
<? if($filters['filter_loc'] == "Y") { ?>
<td align="left" class="subnav"><?=$locationselect ?></td>
<? } ?>
<? if($filters['filter_ven'] == "Y") { ?>
<td align="left" class="subnav"><?=$venueselect ?></td>
<? } ?>
<? if ($col_ct > 3) { ?></tr><tr><? } ?>
<? if($filters['filter_day'] == "Y") { ?>
<td align="left" class="subnav"><?=$dayselect ?></td>
<? } ?>
<? if($filters['filter_month'] == "Y") { ?>
<td align="left" class="subnav"><?=$monthselect ?></td>
<? } ?>
<? if($filters['filter_keyword'] == "Y") { ?>
<td align="left" class="subnav"><?=$keywordbox ?></td>
<? } ?>
</tr>
<tr><td colspan="<?=$col_ct ?>"><input type=submit value="Go"></td></tr>
</form>
</table>

Link to comment
https://forums.phpfreaks.com/topic/178256-what-am-i-missing-here-help/
Share on other sites

ok here is where i think your problem is:

 

as far as i can tell you are not retrieving the values from your form.

There is no

 

$type = $_POST['type'];
$location= $_POST['location'];
$venue= $_POST['venue'];

 

etc.

 

the reason the type query works is because this line has invalid syntax

 

   if ($type <> "") {   

 

this condition will never be met

 

the syntax for not equal to in php is

 

   if ($type != "") {   

 

the same goes for the rest of your code where you have used <> instead of !=

 

on a side note (not that i want to be picky) but you should really start your php tags with <?php rather than the short version of <?. One reason is their On and Off state in php.ini varies with PHP versions and if you use strict XHTML or XML files you will run into lots of errors

 

hope this fixes your problem  :D

I tried what you posted, but still only the type filter works (and the months/days).  However, I did not post the other code to look at. This is in the functions file as well - you can see I do refer to the database form here:

 

$typefilter = "";
$venuefilter = "";
$locationfilter = "";
$dayfilter = "";
$year = "";
$month = "";
$keywordfilter = "";

if ($_POST["month"] <> "") {
$month = $_POST["month"];
} else {
if ($_GET["month"] <> "") {
	$month = $_GET["month"];
} 
}

if ($_POST["year"] <> "") {
$year = $_POST["year"];
} else {
if ($_GET["year"] <> "") {
	$year = $_GET["year"];
} 
}

# this is to handle the new month/year filter
if ($_POST["month_year"] <> "") {
if ($_POST["month_year"] == "all") {
	# limit events to today or later...
	$wheredate .= " and (eventDate >= NOW() or eventDateEnd >= NOW())";
} else {
	$my_fil = array();
	$my_fil = split("/",$_POST["month_year"]);
	$month = $my_fil[0];
	$year = $my_fil[1];

	$wheredate = "and ((DATE_FORMAT(eventDate,'%c') = '$month' and DATE_FORMAT(eventDate,'%Y') = '$year') OR (DATE_FORMAT(eventDateEnd,'%c') = '$month' and DATE_FORMAT(eventDateEnd,'%Y') = '$year'))";
}
} else {
# in case we didn't get a month or year, use the current month and year
if ($month == "") {
	$month = date("n");
}
if ($year == "") {
	$year = date("Y");
}
$wheredate = "and ((DATE_FORMAT(eventDate,'%c') = '$month' and DATE_FORMAT(eventDate,'%Y') = '$year') OR (DATE_FORMAT(eventDateEnd,'%c') = '$month' and DATE_FORMAT(eventDateEnd,'%Y') = '$year'))";
}

if ($month == 12) {
$next_month = 01;
$next_year = $year + 1;
} else {
$next_month = $month + 1;
$next_year = $year;
}

if ($month == 1) {
$last_month = 12;
$last_year = $year - 1;
} else {
$last_month = $month - 1;
$last_year = $year;	
}

$start = 0;
if ($_GET[start] <> "" ) {
$start = $_GET[start];
}
if ($_POST[start] <> "" ) {
$start = $_POST[start];
}

$type = "All";
if ($_GET[type] <> "" ) {
$type = $_GET[type];
}
if ($_POST[type] <> "" ) {
$type = $_POST[type];
}

# let's build some filter select boxes
# this is the month filter; shows 12 months starting from current month,
# no matter which month is currently selected
$months = array("Blank","January","February","March","April","May","June","July","August","September","October","November","December");
$use_month = date("n");
$use_year = date("Y");
$monthselect = "<select name=\"month_year\" style=\"width:110px;\"><option value=\"all\">All Months</option>";
for($i=1;$i<=12;$i++){
if ($use_month == $month) {
	$selected = "selected";
} else {
	$selected = "";
}

$monthselect .= "<option value=\"$use_month/$use_year\" $selected>" . $months[$use_month] . ", $use_year</option>";
if($use_month == "12") {
	$use_month = "1";
	$use_year++;
} else {
	$use_month++;
}
}
$monthselect .= "</select>";

$typeQuery = "SELECT DISTINCT eventCategory FROM eventcal_events where userSubmitted = '0' ORDER BY eventCategory";
$typeList = mysql_query($typeQuery) or die(mysql_error());
$numtypes = mysql_num_rows($typeList);

$typeselect = "<select name=\"type\" style=\"width:110px;\">"; 
if($type == "All"){
$all = "selected";
$typefilter = "";
} else {
if ($type <> "") {
	$typefilter = "AND eventCategory='" . $type . "'";
}
}

$typeselect .= "<option value=\"All\" " . $all . ">All Categories</option>";
while($typearray = mysql_fetch_array($typeList)){
if($typearray["eventCategory"] != "") {
	$selected = "";
	if($typearray["eventCategory"] == $type) {
		$selected = "selected";
	}
	$typeselect .= "<option value=\"" . $typearray["eventCategory"] . "\" " . $selected . ">" . substr($typearray["eventCategory"],0,15) . "</option>";
}
}

$typeselect .= "</select>";
#if($numtypes < 2) {
#	$typeselect = "";
#}

$locationQuery = "SELECT DISTINCT eventLocation FROM eventcal_events where userSubmitted = '0' ORDER BY eventLocation";
$locationList = mysql_query($locationQuery) or die(mysql_error());
$numtypes = mysql_num_rows($locationList);

$locationselect = "<select name=\"location\" style=\"width:110px;\">"; 
if($location == "All"){
$all = "selected";
$locationfilter = "";
} else {
if ($location <> "") {
	$locationfilter = "AND eventLocation='" . $location . "'";
}
}

$locationselect .= "<option value=\"All\" " . $all . ">All Locations</option>";
while($locationarray = mysql_fetch_array($locationList)){
if($locationarray["eventLocation"] != "") {
	$selected = "";
	if($locationarray["eventLocation"] == $location) {
		$selected = "selected";
	}
	$locationselect .= "<option value=\"" . $locationarray["eventLocation"] . "\" " . $selected . ">" . $locationarray["eventLocation"] . "</option>";
}
}
$locationselect .= "</select>";
#if($numtypes < 2) {
#	$locationselect = "";
#}

$venueQuery = "SELECT DISTINCT eventVenue FROM eventcal_events where userSubmitted = '0' ORDER BY eventVenue";
$venueList = mysql_query($venueQuery) or die(mysql_error());
$numtypes = mysql_num_rows($venueList);

$venueselect = "<select name=\"venue\" style=\"width:110px;\">"; 
if($venue == "All"){
$all = "selected";
$venuefilter = "";
} else {
if ($venue <> "") {
	$venuefilter = "AND eventVenue='" . $venue . "'";
}
}
$venueselect .= "<option value=\"All\" " . $all . ">All Venues</option>";

while($venuearray = mysql_fetch_array($venueList)){
if($venuearray["eventVenue"] != "") {
	$selected = "";
	if($venuearray["eventVenue"] == $venue) {
		$selected = "selected";
	}
	$venueselect .= "<option value=\"" . $venuearray["eventVenue"] . "\" " . $selected . ">" . $venuearray["eventVenue"] . "</option>";
}
}
$venueselect .= "</select>";
#if($numtypes < 2) {
#	$venueselect = "";
#}

$dow = "";
if ($_GET['dow'] <> "") {
$dow = $_GET['dow'];
} 
if ($_POST['dow'] <> "") {
$dow = $_POST['dow'];
}
if ($dow == 7) {
$dow = "";
}

$dayselect = "<select name=\"dow\" style=\"width:110px;\">";
if ($dow == "") {
$selected = "selected";
} else {
$selected = "";
}
$dayselect .= "<option value=\"7\" " . $selected . ">All Days</option>";
if ($dow == 1) {
$selected = "selected";
} else {
$selected = "";
}
$dayselect .= "<option value=\"1\" " . $selected . ">Monday</option>";
if ($dow == 2) {
$selected = "selected";
} else {
$selected = "";
}
$dayselect .= "<option value=\"2\" " . $selected . ">Tuesday</option>";
if ($dow == 3) {
$selected = "selected";
} else {
$selected = "";
}
$dayselect .= "<option value=\"3\" " . $selected . ">Wednesday</option>";
if ($dow == 4) {
$selected = "selected";
} else {
$selected = "";
}
$dayselect .= "<option value=\"4\" " . $selected . ">Thursday</option>";
if ($dow == 5) {
$selected = "selected";
} else {
$selected = "";
}
$dayselect .= "<option value=\"5\" " . $selected . ">Friday</option>";
if ($dow == 6) {
$selected = "selected";
} else {
$selected = "";
}
$dayselect .= "<option value=\"6\" " . $selected . ">Saturday</option>";
if ($dow == "0") {
$selected = "selected";
} else {
$selected = "";
}
$dayselect .= "<option value=\"0\" " . $selected . ">Sunday</option>";
$dayselect .= "</select>";


if ($dow <> "") {
$day_where = " and (DATE_FORMAT(eventDate,'%w') = '$dow' or DATE_FORMAT(eventDateEnd,'%w') = '$dow')";
} else {
$day_where = "";
}

# keyword filter
$keyword = "";
if ($_POST['keyword'] <> "Enter Keyword(s)" and $_POST['keyword'] <> "") {
$keyword = $_POST['keyword'];
$keywordfilter = " and (eventTitle like '%$keyword%' or eventDescription like '%$keyword%')";
} else {
$keyword = "Enter Keyword(s)";
$keywordfilter = "";
}

$keywordbox = "<input type=text name=keyword id=keyword value='$keyword' class='subnav' size=20px onfocus=\"this.value='';\">";

$countQuery = "select * from eventcal_events where userSubmitted = '0' $wheredate $day_where $typefilter $venuefilter $locationfilter $keywordfilter";
$countList = mysql_query($countQuery) or die(mysql_error());
$record_count = mysql_num_rows($countList);

list($eventsperpage) = mysql_fetch_array(mysql_query("SELECT value FROM eventcal_settings WHERE variable='events_per_page'")) or die(mysql_error());

if($eventsperpage == "All"){
$limit = "";
$eventsperpage = $record_count;
} else {
$limit = "limit  " . $start . ", " . ($eventsperpage + 1);
}

list($sort) = mysql_fetch_array(mysql_query("SELECT value FROM eventcal_settings WHERE variable='sort'"));
if ($sort == "date") {
$order_it = "eventDate, eventTitle";
} else {
$order_it = "eventTitle";
}

 

 

Thank you so much for the time!  I tried replacing all instances as you said.  However, I still  have the problem of the type, month, day, year and keyword all working fine - but the venue and category are not working. I just don't know what it is. I've poured and poured over the code and double checked spelling, etc.  The filter dropdowns work fine, in that they show all of the entries from the database and are chooseable - they just don't do anything when chosen.

 

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.