Hello guys I am having a problem regarding queries in PHP because I not very familiar with queries especially inner join function, I need to make a profile page wherein it will display records from tblpatient_pass and tblpatient_info connected by (PK)MR_no from tblpatient_info and (FK)RelationMR_no from tblpatient_pass here is my sample code:
<?php
$query1 = "SELECT tblpatient_pass.RelationMR_no, tblpatient_pass.username, tblpatient_pass.password, tblpatient_pass.email_address, tblpatient_info.lastname, tblpatient_info.firstname, tblpatient_info.mname
FROM tblpatient_pass INNER JOIN tblpatient_info ON tblpatient_pass.RelationMR_no=tblpatient_info.MR_no
";
$numrows = mysql_query($query1);
if ($numrows!=0)
{
while ($row = mysql_fetch_array($query1))
{
$username = $_SESSION['username'];
$query = mysql_query("SELECT * FROM tblpatient_pass WHERE username =".$username);
$result = mysql_query($query) or die(mysql_error());
while ($patient = mysql_fetch_array($result))
{
echo $patient['RelationMR_no'].'<br>';
echo $patient['username'].'<br>';
echo $patient['password'].'<br>';
echo $patient['email_address'].'<br>';
echo $patient['lastname'].'<br>';
echo $patient['firstname'].'<br>';
echo $patient['mname'].'<br>';
echo $patient['gender'].'<br>';
echo $patient['age'].'<br>';
}
}
}
?>
Please tell me how can I select a record from two tables based on the username of the patient