VickP07
12-03-2011, 03:25 AM
Hey guys so i have a page where i am creating a table to show all patient data
the select statement is working and the correct data is being displayed buttttttttttt i am seeing that it is repeating some patient data more than once.
Here is how my table looks:
Medical Record | First Name | Last Name |Medication Name| Dose | Unit Of Measurement | Appointment Description | Visit Notes |
So then it should display data like this:
111-1212AB | Chad | Smith | Allegra | 15 | mg | patient will return next week | patient's blood was sent to lab|
111-1212AB | Chad | Smith | Zyrtec| 15 | mg | appointment desc goes here | patient's blood was sent to lab again|
but i am seeing that some patients repeat twice so the above example will be displayed 4 times making it seem like that patient has been assigned 4 individual medications and appointment desc and visit notes
here is my sql statement:
$sql2 ="
SELECT patients.med_rec, patients.fname, patients.lname, medications.med_name, prescriptions.dose, UOM.name, appointments.descr, notes.visit_note
FROM prescriptions, patients, medications, UOM, appointments, notes
WHERE prescriptions.pat_id = patients.patient_id
AND medications.medication_id = prescriptions.med_id
AND UOM.unit_id = prescriptions.uom_id
AND appointments.pat_id = patients.patient_id
AND notes.pat_id = patients.patient_id;
";
here is where i create my table displaying all the patient data:
<table border="2" CELLPADDING="2" CELLSPACING="5" width ="1000">
<tr>
<th>Medical Record</th>
<th>First Name</th>
<th>Last Name</th>
<th>Medication Name</th>
<th>Dose</th>
<th>Unit Of Measurement</th>
<th>Appointment Description</th>
<th>Visit Notes</th>
</tr>
<?
#test if select statement works
$result2 = mysql_query( $sql2 );
$result2 or die("My query ($sql2) failed." );
//echo "<hr>DEBUG SQL: " . $sql2 . "<hr/>\n";
#While statement used to pass data from DB into tables
while( $row = mysql_fetch_array( $result2 ) ) { ?>
<br />
<tr>
<td><?=$row['med_rec']?></td>
<td><?=$row['fname']?></td>
<td><?=$row['lname']?></td>
<td><?=$row['med_name']?></td>
<td><?=$row['dose']?></td>
<td><?=$row['name']?></td>
<td><?=$row['descr']?></td>
<td><?=$row['visit_note']?></td>
</tr>
<? } ?>
</table>
the select statement is working and the correct data is being displayed buttttttttttt i am seeing that it is repeating some patient data more than once.
Here is how my table looks:
Medical Record | First Name | Last Name |Medication Name| Dose | Unit Of Measurement | Appointment Description | Visit Notes |
So then it should display data like this:
111-1212AB | Chad | Smith | Allegra | 15 | mg | patient will return next week | patient's blood was sent to lab|
111-1212AB | Chad | Smith | Zyrtec| 15 | mg | appointment desc goes here | patient's blood was sent to lab again|
but i am seeing that some patients repeat twice so the above example will be displayed 4 times making it seem like that patient has been assigned 4 individual medications and appointment desc and visit notes
here is my sql statement:
$sql2 ="
SELECT patients.med_rec, patients.fname, patients.lname, medications.med_name, prescriptions.dose, UOM.name, appointments.descr, notes.visit_note
FROM prescriptions, patients, medications, UOM, appointments, notes
WHERE prescriptions.pat_id = patients.patient_id
AND medications.medication_id = prescriptions.med_id
AND UOM.unit_id = prescriptions.uom_id
AND appointments.pat_id = patients.patient_id
AND notes.pat_id = patients.patient_id;
";
here is where i create my table displaying all the patient data:
<table border="2" CELLPADDING="2" CELLSPACING="5" width ="1000">
<tr>
<th>Medical Record</th>
<th>First Name</th>
<th>Last Name</th>
<th>Medication Name</th>
<th>Dose</th>
<th>Unit Of Measurement</th>
<th>Appointment Description</th>
<th>Visit Notes</th>
</tr>
<?
#test if select statement works
$result2 = mysql_query( $sql2 );
$result2 or die("My query ($sql2) failed." );
//echo "<hr>DEBUG SQL: " . $sql2 . "<hr/>\n";
#While statement used to pass data from DB into tables
while( $row = mysql_fetch_array( $result2 ) ) { ?>
<br />
<tr>
<td><?=$row['med_rec']?></td>
<td><?=$row['fname']?></td>
<td><?=$row['lname']?></td>
<td><?=$row['med_name']?></td>
<td><?=$row['dose']?></td>
<td><?=$row['name']?></td>
<td><?=$row['descr']?></td>
<td><?=$row['visit_note']?></td>
</tr>
<? } ?>
</table>