Aftab Ali Aftab Ali - 3 days ago 5
MySQL Question

How to fetch data from two tables info using php

I want to get data from two tables. I have patient first name and last name in one table and appointment time in other table. I am using following way but it gives an error:

SELECT
PatientMaster.PatientFirstName,
PatientMaster.PatientLastName,
ProviderAppointmentListings.AppointmentTime
FROM PatientMaster
JOIN ProviderAppointmentListings
ON PatientMaster.PatientID = ProviderAppointmentListings.PatientID


$result = mysql_query($query) OR die(mysql_error());
$rows = array();
while($row = mysql_fetch_assoc($result)) {
$rows[] = $row;
}
echo json_encode($rows);


it prints here query empty

Answer

[EDITED]

Try:

$query="SELECT PatientMaster.FirstName,PatientMaster.LastName,ProviderAppointmentListings.AppointmentTime 
FROM PatientMaster JOIN ProviderAppointMentListings ON PatientMaster.PatientID = ProviderAppointmentListings.PatientId";

$result = mysql_query($query) or die(mysql_error());

If a MySQL error appears, then there must be something wrong with your query.

Comments