I have written a simple html page with drop-down choices and a keyword search box. I have done this successfully. The result is a table with two columns, generated from the page and code below. The first column has a library name. I want each of these library names to be a hyperlink to the specific record of that library. All this information is in one table called 'libdir'. There is an 'id' field that is auto-incrementing and unique to each record. I have tried to link to each record using a url with an id attached to it, but I don't quite know the syntax. I have embedded a test URL into the $LIBNAME variable, but it needs to replaced with the correct URL and syntax.
I want to be able to click on the resulting link and bring up a record with a table format, with fields like this:
Library:
Street:
City:
Zip:
Can anyone help with this? Here is the code of my page:
<html>
<head>
<title>Public Library Search Results</title>
</head>
<body>
<h1>Public Library Search Results</h1>
<?php
@ $db = mysql_connect("xx.xx.xx.xx.xx", "user", "pass
if (!$db)
{
echo "Error: Could not connect to database. Please try again later.";
exit;
}
$searchtype = $POST["searchtype"];
$searchterm = $POST["searchterm"];
$searchterm = trim(preg_replace("/[A-Za-z0-9 -. ]/","",$searchterm));
mysql_select_db("libdev");
$query = "select * from libdir where ".$searchtype ." Like '%".$searchterm."%' ORDER by name";
$result = mysql_query($query);
echo $query;
// start results formatting
echo "<TABLE BORDER=1>";
echo "<TR><TH>Library</TH><TH>City</TH></TR>";
// format results by row
while ($row = mysql_fetch_array($sql_result))
{
$LIBNAME = $row["name"];
$CITY = $row["city"];
echo "<TR><TD><A HREF=/"http://url.anywhere.com/">$LIBNAME</A></TD><TD>$CITY</TD></TR>";
}
echo "</p>";
echo "</TABLE>";
// free resources and close connection
mysql_free_result($sql_result);
mysql_close($connection);
?>
</body>
</html>