View Single Post
  #5 (permalink)  
Old 05-10-2004, 04:54 PM
bufhal bufhal is offline
WebProWorld New Member
 
Join Date: May 2004
Location: Western New York
Posts: 17
bufhal RepRank 0
Default

I tried to select all the fields and that did not work-still returned the three. I have 4 records of 12 fields of data in the MySQL database. I will keep playing with it. Here is another version for results.php
Thank for you help..

<?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(".com", "wny", "immunize"); //creates a connection

if (!$SQLlink)
Die("Couldn't connect to the db server."); // display error message on error

if (!mysql_select_db("immunizewny", $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 date, agency, city 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=3>No results found</td></tr>";

} else {
forEach ($agencies as $agency) { // display row for each result (eg. you can have more agencies in one town)
$output .= "<tr>";
$output .= "<td>".$agency["date"]."</td>";
$output .= "<td>".$agency["agency"]."</td>";
$output .= "<td>".$agency["city"]."</td>";



$output .= "</tr>\n";
}
}

$output .= "</table>\n";

echo $output;

?>

Close window
</body>
</html>
Reply With Quote