can anybody help me how I can use four tables at the same time with different conditions to fetch records from my database?
this is my sql code that im trying to modify because this is only for two tables:
<?php
session_start();
if (isset($_SESSION['username']))
{
include("database.php");
$username = $_SESSION['username'];
$query = "SELECT *
FROM tblpatient_pass p, tblpatient_info i
WHERE p.RelationMR_no = i.MR_no
AND p.username='$username'"; //this is the SQl code that Im trying to modify
$result = mysql_query($query) or die(mysql_error());
$patient = mysql_num_rows($result);
if ($patient!=0)
{
while ($row = mysql_fetch_array($result))
{
$dMR_no = $row[0];
$dusername = $row[1];
$dpassword = $row[2];
$demail = $row[3];
$dlname = $row[5];
$dfname = $row[6];
$dgender = $row[11];
$dmname = $row[7];
$dage = $row[9];
$dcontact_no = $row[12];
$dlocation = $row[8];
// print_r($row);
}
}
else
{
die(mysql_error());
}
}
else
die("Please Login to view this page");
?>
this is the information of the tables that I want to use
tbllabchem: //this is the primary table
LabID_No int(11) No None auto_increment
RelationMR_No int(11) UNSIGNED No None
RelationDoc_ID int(11) UNSIGNED No None
Date varchar(50) latin1_swedish_ci No None
Random_BloodSugar varchar(45) latin1_swedish_ci No None
Glucose varchar(45) latin1_swedish_ci No None
Bun varchar(45) latin1_swedish_ci No None
Creatinine varchar(45) latin1_swedish_ci No None
bua varchar(45) latin1_swedish_ci No None
Total_Cholesterol varchar(45) latin1_swedish_ci No None
Triglyceride varchar(45) latin1_swedish_ci No None
Hdl varchar(45) latin1_swedish_ci No None
Ldl varchar(45) latin1_swedish_ci No None
Vldl varchar(45) latin1_swedish_ci No None
Oral_GlucoseTolerance varchar(45) latin1_swedish_ci No None
Glucose_ChallengeTest varchar(45) latin1_swedish_ci No None
Calciums varchar(45) latin1_swedish_ci No None
Others varchar(45) latin1_swedish_ci No None
Total_Protein varchar(45) latin1_swedish_ci No None
Albumin varchar(45) latin1_swedish_ci No None
Globulin varchar(45) latin1_swedish_ci No None
A/G_Ratio varchar(45) latin1_swedish_ci No None
Sodium varchar(45) latin1_swedish_ci No None
Potassium varchar(45) latin1_swedish_ci No None
Chloride varchar(45) latin1_swedish_ci No None
Total_Bilirubin varchar(45) latin1_swedish_ci No None
Direct_Bilirubin varchar(45) latin1_swedish_ci No None
Indirect_Bilirubin varchar(45) latin1_swedish_ci No None
Sgot varchar(45) latin1_swedish_ci No None
Sgpt varchar(45) latin1_swedish_ci No None
Alk_Phos varchar(45) latin1_swedish_ci No None
Med_Tech varchar(45) latin1_swedish_ci No None
Pathologist
this is the tbldoctor_info where I want to get the name of the doctor base on the
RelationDoc_ID from tblbloodchem and ID_no from tbldoctor_info
ID_No int(10) UNSIGNED No None auto_increment
LastName varchar(45) latin1_swedish_ci No None
FirstName varchar(45) latin1_swedish_ci No None
MName varchar(45) latin1_swedish_ci No None
Age varchar(45) latin1_swedish_ci No None
Gender varchar(45) latin1_swedish_ci No None
Address varchar(45) latin1_swedish_ci No None
Specialist varchar(45) latin1_swedish_ci No None
License_No int(10)
I also want to get the name of the patient from tblpatient_info based on the RelationMR_no from tblbloodchem and MR_no from tblpatient_info
tblpatient_info
MR_No int(10) UNSIGNED No None auto_increment
LastName varchar(45) latin1_swedish_ci No None
FirstName varchar(45) latin1_swedish_ci No None
MName varchar(45) latin1_swedish_ci No None
Address varchar(45) latin1_swedish_ci Yes NULL
Age int(10) No None
BP int(10) No None
Gender varchar(45) latin1_swedish_ci No None
Contact_No int(11) No None
Weight int(10) No None
Temperature varchar(45) latin1_swedish_ci No None
I you where confused with my explanation, don't hesitate to ask me :)