I have below a quite simple php page which queries a database table of all
records and outputs the result. However on this page I only output 3 of the
fields and I would like to click on a particular row which would then bring
up a detail page (which displays all the fields (perhaps 10 or more) of that
record).
Do I create another php file called detail.php which includes the line:
$sql = 'SELECT * FROM `link` WHERE link_id = $id;
and then alter the echo line below to something like:
echo "<TR><TD><a
href=detail.php?link_id=$id</TD><TD>$title</TD><TD>$description</TD></TR>";
which would then pass the variable $id into the sql statement in detail.php.
??
Any advice on the next steps would be welcome.
Cheers
Phil
<html>
<body>
<?php
// listrecords.php
// lists brief details of records (1 record per row)
$localhost = 'localhost';
$username = 'username';
$password = 'password';
$database = 'database';
$dbconnection = mysql_connect($localhost, $username, $password);
if (! $dbconnection)
{
die ("Couldn't connect to MySQL");
exit;
}
$db=mysql_select_db($database, $dbconnection);
if (!$db)
{
echo "Could not select database";
exit;
}
$sql = 'SELECT `link_id`,`title`,`description` FROM `links` LIMIT 0, 30';
$mysql_result=mysql_query($sql,$dbconnection);
$num_rows=mysql_num_rows($mysql_result);
if ($num_rows == 0) {
echo "Sorry, we have no records";
}
else
{
echo "<TABLE ALIGN=\"CENTER\" BORDER=\"1\">";
echo "<TR><TH>Record ID</TH><TH>Title</TH><TH>Description</TH></TR>";
while ($row=mysql_fetch_array($mysql_result))
{
$id=$row["link_id"];
$title=$row["title"];
$description=$row["description"];
echo "<TR><TD>$id</TD><TD>$title</TD><TD>$description</TD></TR>";
}
}
?>
</TABLE>
</body>
</html>