Forgive me if this is too long/too simple - I am new to this!
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:
[code=php]
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 `trialrestauran ts`
WHERE `posttown` LIKE CONVERT(_utf8 '$town' USING latin1) COLLATE latin1_german2_ ci");
}
else{
$query = mysql_db_query( $db, "SELECT * FROM `trialrestauran ts`
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='#0 00000' cellpadding='4' cellspacing='0' >\n";
$id = $row["ID"];
while ($row = mysql_fetch_arr ay($query))
echo "
<tr>\n<td align='left'><a href='details.p hp?id=$id'>".$r ow[name]."</td>
<td align='left'><a href='details.p hp?id=$id'>".$r ow[location]."</td>
<td align='left'><a href='details.p hp?id=$id'>".$r ow[cuisine]."</a></td>
\n</tr>\n";
echo "</table>";[/code]
Template Page:
[code=php]
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 = "trialrestauran ts";
$query = mysql_db_query( $db, "SELECT * FROM 'trialrestauran ts' WHERE 'ID' LIKE CONVERT(_utf8 '$id'USING latin1) COLLATE latin1_german2_ ci ");
$query = mysql_query($qu ery) or die(mysql_error ());
$numrows = mysql_num_rows( $query);
if ( $numrows > 0 ) { // if the id was found
while ( $details = mysql_fetch_arr ay($query) ) {
echo "Town: ". $details['town'];
echo "Cuisine: ". $details['cuisine'];
}
}else { // if it was not found
echo "error: invalid id.";
}
[/code]
Thanks in advance for any help or ideas.
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:
[code=php]
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 `trialrestauran ts`
WHERE `posttown` LIKE CONVERT(_utf8 '$town' USING latin1) COLLATE latin1_german2_ ci");
}
else{
$query = mysql_db_query( $db, "SELECT * FROM `trialrestauran ts`
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='#0 00000' cellpadding='4' cellspacing='0' >\n";
$id = $row["ID"];
while ($row = mysql_fetch_arr ay($query))
echo "
<tr>\n<td align='left'><a href='details.p hp?id=$id'>".$r ow[name]."</td>
<td align='left'><a href='details.p hp?id=$id'>".$r ow[location]."</td>
<td align='left'><a href='details.p hp?id=$id'>".$r ow[cuisine]."</a></td>
\n</tr>\n";
echo "</table>";[/code]
Template Page:
[code=php]
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 = "trialrestauran ts";
$query = mysql_db_query( $db, "SELECT * FROM 'trialrestauran ts' WHERE 'ID' LIKE CONVERT(_utf8 '$id'USING latin1) COLLATE latin1_german2_ ci ");
$query = mysql_query($qu ery) or die(mysql_error ());
$numrows = mysql_num_rows( $query);
if ( $numrows > 0 ) { // if the id was found
while ( $details = mysql_fetch_arr ay($query) ) {
echo "Town: ". $details['town'];
echo "Cuisine: ". $details['cuisine'];
}
}else { // if it was not found
echo "error: invalid id.";
}
[/code]
Thanks in advance for any help or ideas.
Comment