You were so gracious in helping me get this code so far, I thank you again...
the problem is that this is a report for how many exams were done in a day sorted by patient and what procedures and fees were associated with it
So it is suppose to displa something like this
Exams Performed Today: $totalexams
ExamID
PatientName
ExamDate
Procedre1:[if performed]
procedure2: [if performed]
etc
you get the picture
So the problem is if $totalexams says: "4" but only displays two exams, I cannot figure out why its not displaying all the exams and its information.
Heres the code:
<?
$connect = @mysql_pconnect($dbserver, $dbuser, $dbpass) or die("Could not Connect to Server: Query 1");
$db = @mysql_select_db($dbname, $connect) or die("could not select DB");
$sql = "SELECT ed.ExamID, ed.DoctorID, dc.DoctorID, dc.DoctorFirstName, dc.DoctorLastName, x.ExamDate, x.ExamID, pa.PatientFirstName, pa.PatientLastName, xf.ExamFee,
pr.ProcedureID, pr.ProcedureName FROM exams AS x, examfees AS xf, procedure_tbl AS pr, patients AS pa,
examdoctors AS ed, doctors AS dc WHERE x.ExamID = xf.ExamID AND x.ExamID = ed.ExamID AND
xf.ProcedureID = pr.ProcedureID AND x.PatientID = pa.PatientID AND xf.ExamFee!=0 AND ed.DoctorID = dc.DoctorID AND
x.ExamDate >= Date_Sub(CURDATE(), INTERVAL 10 YEAR) ORDER BY ExamDate DESC, ProcedureID DESC";
$result = mysql_query($sql, $connect) or die("Could not Execute Query #1");
$num_rows = mysql_num_rows($result);
echo "<b><u>Exams Performed Today:</u></b> $num_rows";
$ExamTotals = '';
$ExamID = '';
While ($row = mysql_fetch_array($result)) {
$DoctorID = $row['DoctorID'];
$DoctorFirstName = $row['DoctorFirstName'];
$DoctorLastName = $row['DoctorLastName'];
$PrevExamID = $ExamID;
$ExamDate = $row['ExamDate'];
$ExamID = $row['ExamID'];
$ProcedureID = $row['ProcedureID'];
$ProcedureName = $row['ProcedureName'];
$ProcedureFee = $row['ExamFee'];
$PatientFirstName = $row['PatientFirstName'];
$PatientLastName = $row['PatientLastName'];
if ($PrevExamID == $ExamID) {
if ($ProcedureID == 0) {
$ExamTotals += $ProcedureFee;
echo "<br><br><b>$ProcedureName:</b> \$$ProcedureFee";
}
else {
echo "<br><b>$ProcedureName:</b> \$$ProcedureFee";
}
}
else {
echo '<br><hr><b>Patient Name:</b> ' ."$PatientFirstName $PatientLastName";
echo '<br><b>ExamDate:</b> ' . $ExamDate;
echo '<br><b>Doctor:</b> ' . $DoctorLastName;
echo '<br><b>ExamID:</b> ' . "$ExamID<br>";
echo "<br><b><u>Procedures:</U></b><br>";
echo "<br><b>$ProcedureName:</b> \$$ProcedureFee";
}
}
echo "<BR><hr><b>Exam Totals:</b>
<b><font color=\"#FF0000\" face=\"Arial, Helvetica, sans-serif \">\$$ExamTotals.00</font></b>";
?>