Hello;
I am rather stuck on this and I hope someone can take a look and see what is wrong.
I have two files 1.) index.php which contains 3 dropdown menus Agency, City and Date-and 2.) results.php which prints results to screen in a popup. So far, I am getting only one result for City. Can someone take a look and see why I cannot get results for the other two dropdowns?
I appreciate your feedback:p
Here is index.php:
$data = mysql_query("SELECT date, agency, city FROM agencies ORDER BY date, agency, city ASC;
");
if (!$data)
Die(mysql_error()); // display MySQL error message on error
$agencies = Array();
while($row = mysql_fetch_array($data)) { // assign results into arrays
$dates[] = $row["date"];
$agencies[] = $row["agency"];
$cities[] = $row["city"];
}
$dates = Array_Unique($dates); // remove duplicate values
$agencies = Array_Unique($agencies);
$cities = Array_Unique($cities);
Sort($dates); // sort arrays
Sort($agencies);
Sort($cities);
$date_out = "<select name='date' onchange=\"window.open('results.php?action=date&value='+this.value, 'agencyWin', 'location=yes,left=20,top=20');\">";
$agency_out = "<select name='agency' onchange=\"window.open('results.php?action=agency&value='+this.value, 'agencyWin', 'location=yes,left=20,top=20');\">";
$city_out = "<select name='city' onchange=\"window.open('results.php?action=city&value='+this.value, 'agencyWin', 'location=yes,left=20,top=20');\">";
$date_out .= "<option>-- select date ---</option>";
$agency_out .= "<option>-- select agency ---</option>";
$city_out .= "<option>-- select city ---</option>";
//forEach ($dates as $value)
//$date_out .= "<option value='$value'>$value</option>";
forEach ($dates as $value)
$date_out .= "<option value='$value'>".date('m/d/Y',strtotime($value))."</option>";
forEach ($agencies as $value)
$agency_out .= "<option value='$value'>$value</option>";
forEach ($cities as $value)
$city_out .= "<option value='$value'>$value</option>";
$date_out .= "</select>\n";
$agency_out .= "</select>\n";
$city_out .= "</select>\n";
echo $date_out."";
echo $agency_out."";
echo $city_out."<BR>";
?>
Here is results.php
<?php
if (!IsSet($action) || !IsSet($value)) // check if both vars are set
Die("Both vars must be set");
if (Trim($value) == "") // check if value is non-blank
Die("Value can't be left blank");
if ($action != "date" && $action != "agency" && $action != "city")
Die("Unknown action requested");
// Connection to the db server and select active db
$SQLlink = @mysql_connect("sql13.com", "bufhal2", "password"); //creates a connection
if (!$SQLlink)
Die("Couldn't connect to the db server."); // display error message on error
if (!mysql_select_db("bufhal2_wnyaic", $SQLlink))
Die("Couldn't access database."); // display error message on error
// escape data from user
if (ini_get('magic_quotes_gpc')) { // unescaping data if needed
$value = StripSlashes($value);
}
$value = mysql_escape_string($value); // escaping data for MySQL db
$data = mysql_query("SELECT * FROM agencies WHERE $action = '$value'"); // perform a query
if (!$data)
Die(mysql_error()); // display MySQL error message on error
$agencies = Array();
while($row = mysql_fetch_array($data)) {
$agencies[] = $row;
}
$output = "<table border=1>\n";
if (mysql_num_rows($data) == 0) { // in the case of no results found - display alert message
$output .= "<tr><td colspan=4>No results found</td></tr>";
} else {
$output .= "<tr>";
$output .= "<td align=\"center\"><b>Date</b></td>";
$output .= "<td align=\"center\"><b>Agency</b></td>";
$output .= "<td align=\"center\"><b>City</b></td>";
$output .= "<td align=\"center\"><b>Time</b></td>";
$output .= "<td align=\"center\"><b>Day</b></td>";
$output .= "<td align=\"center\"><b>Location</b></td>";
$output .= "<td align=\"center\"><b>Building or Room</b></td>";
$output .= "<td align=\"center\"><b>Street</b></td>";
$output .= "<td align=\"center\"><b>Zip</b></td>";
$output .= "<td align=\"center\"><b>Phone</b></td>";
$output .= "<td align=\"center\"><b>Contact</b></td>";
$output .= "</tr>";
forEach ($agencies as $agency) { // display row for each result (eg. you can have more agencies in one town)
$output .= "<tr>";
$output .= "<td align=\"center\">".$agency["date"]."</td>";
$output .= "<td align=\"center\">".$agency["agency"]."</td>";
$output .= "<td align=\"center\">".$agency["city"]."</td>";
$output .= "<td align=\"center\">".$agency["time"]."</td>";
$output .= "<td align=\"center\">".$agency["day"]."</td>";
$output .= "<td align=\"center\">".$agency["location"]."</td>";
$output .= "<td align=\"center\">".$agency["building_room"]."</td>";
$output .= "<td align=\"center\">".$agency["street"]."</td>";
$output .= "<td align=\"center\">".$agency["zip"]."</td>";
$output .= "<td align=\"center\">".$agency["phone"]."</td>";
$output .= "<td align=\"center\">".$agency["contact"]."</td>";
$output .= "</tr>\n";
}
}
$output .= "</table>\n";
echo $output;
?>
[