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>$descrip tion</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_selec t_db($database, $dbconnection);
if (!$db)
{
echo "Could not select database";
exit;
}
$sql = 'SELECT `link_id`,`titl e`,`description ` FROM `links` LIMIT 0, 30';
$mysql_result=m ysql_query($sql ,$dbconnection) ;
$num_rows=mysql _num_rows($mysq l_result);
if ($num_rows == 0) {
echo "Sorry, we have no records";
}
else
{
echo "<TABLE ALIGN=\"CENTER\ " BORDER=\"1\">";
echo "<TR><TH>Re cord ID</TH><TH>Title</TH><TH>Descript ion</TH></TR>";
while ($row=mysql_fet ch_array($mysql _result))
{
$id=$row["link_id"];
$title=$row["title"];
$description=$r ow["descriptio n"];
echo "<TR><TD>$i d</TD><TD>$title</TD><TD>$descrip tion</TD></TR>";
}
}
?>
</TABLE>
</body>
</html>
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>$descrip tion</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_selec t_db($database, $dbconnection);
if (!$db)
{
echo "Could not select database";
exit;
}
$sql = 'SELECT `link_id`,`titl e`,`description ` FROM `links` LIMIT 0, 30';
$mysql_result=m ysql_query($sql ,$dbconnection) ;
$num_rows=mysql _num_rows($mysq l_result);
if ($num_rows == 0) {
echo "Sorry, we have no records";
}
else
{
echo "<TABLE ALIGN=\"CENTER\ " BORDER=\"1\">";
echo "<TR><TH>Re cord ID</TH><TH>Title</TH><TH>Descript ion</TH></TR>";
while ($row=mysql_fet ch_array($mysql _result))
{
$id=$row["link_id"];
$title=$row["title"];
$description=$r ow["descriptio n"];
echo "<TR><TD>$i d</TD><TD>$title</TD><TD>$descrip tion</TD></TR>";
}
}
?>
</TABLE>
</body>
</html>
Comment