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:

	$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

Recommended Answers

All 3 Replies

FROM tblpatient_pass p, tblpatient_info i
where p.RelationMR_no = i.MR_no
and username='$username'

thank you this helped me much :)
but still I get some error in my PHP project but I'll rather ask it in PHP forum,, thanks

I just came back here to say that your SQL codes worked, and also to say Thank you again! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.