I have a database containing 2 tables - db and details. On clicking a particular field in db column ('Issued to') of any record in the "db" table I want to display the all the fields of the "details" table matching with the particular column "Issued to" in "details" table. In my code the page shows all the matching results of both the tables. I just want the selected (clicked on) record result. The code is as follows-
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = "";
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$sql = 'SELECT a.`Issued to`, b.Name, b.DOB, b.Discipline, b.Designation, b.PlaceOfPosting, b.PhoneNo, b.Email
FROM db a, details b
WHERE a.`Issued to` = b.`Issued to`';
mysql_select_db('testdb');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_array($retval, MYSQL_ASSOC))
{
echo "Name:{$row['Name']} <br> ".
"Date Of Birth:{$row['DOB']} <br> ".
"Discipline:{$row['Discipline']} <br> ".
"Designation:{$row['Designation']} <br> ".
"Place of Posting:{$row['PlaceOfPosting']} <br> ".
"Phone: {$row['PhoneNo']} <br> ".
"Email Id: {$row['Email']} <br> ".
"--------------------------------<br>";
}
mysql_close($conn);
?>
Aucun commentaire:
Enregistrer un commentaire