I have an htm page with a "post" form. This has 2 droplists, the variables of which are posted to a php page. This page queries a mySQL database and echoes in rows any matching records.
At present each result row lists the info from the database fields name, location and type. I had put an "a href=" around these results so if a row is clicked, it opened a seperate htm page with all the details of that particular file.
I have 1000 records on my database and currently have 1000 htm pages. This means I have to update1000 pages every time something changes.
What I would really like to do is have it so that when a row is clicked on, a php page is opened. this page is a template so that all the info that I need from the database is inserted into the page
By having a php template, I only need update 1 page as the info is different every time.
I enclose the code that I am using on the 2 php pages. Can anyone see why it isn't working? What do I need to do. I am right at the boundary of my understanding here!
List Page:
Expand|Select|Wrap|Line Numbers
- mysql_connect ($host, $user, $password)
- or die ('I cannot connect to the database
- because: ' . mysql_error());
- mysql_select_db ($db);
- $town = $_POST["town"];
- $cuisine =$_POST["cuisine"];
- if ($cuisine == "All Cuisines") {
- $query = mysql_db_query($db, "SELECT * FROM `trialrestaurants`
- WHERE `posttown` LIKE CONVERT(_utf8 '$town' USING latin1) COLLATE latin1_german2_ci");
- }
- else{
- $query = mysql_db_query($db, "SELECT * FROM `trialrestaurants`
- WHERE `posttown` LIKE CONVERT(_utf8 '$town' USING latin1) COLLATE latin1_german2_ci
- AND `cuisine` LIKE CONVERT(_utf8 '$cuisine' USING latin1) COLLATE latin1_german2_ci ");
- }
- echo "<table width='100%' border='0' bordercolor='#000000' cellpadding='4' cellspacing='0'>\n";
- $id = $row["ID"];
- while ($row = mysql_fetch_array($query))
- echo "
- <tr>\n<td align='left'><a href='details.php?id=$id'>".$row[name]."</td>
- <td align='left'><a href='details.php?id=$id'>".$row[location]."</td>
- <td align='left'><a href='details.php?id=$id'>".$row[cuisine]."</a></td>
- \n</tr>\n";
- echo "</table>";
Expand|Select|Wrap|Line Numbers
- mysql_connect ($host, $user, $password)
- or die ('I cannot connect to the database
- because: ' . mysql_error());
- mysql_select_db ($db);
- $id = $_GET["ID"]; $details_table = "trialrestaurants";
- $query = mysql_db_query($db, "SELECT * FROM 'trialrestaurants' WHERE 'ID' LIKE CONVERT(_utf8 '$id'USING latin1) COLLATE latin1_german2_ci ");
- $query = mysql_query($query) or die(mysql_error());
- $numrows = mysql_num_rows($query);
- if ( $numrows > 0 ) { // if the id was found
- while ( $details = mysql_fetch_array($query) ) {
- echo "Town: ". $details['town'];
- echo "Cuisine: ". $details['cuisine'];
- }
- }else { // if it was not found
- echo "error: invalid id.";
- }