I have the following code that is confusing the hell out of me. In order to simplify things for me, i just did 4 seperate queries.
Now, what I would like to do is to take the information that I have pulled and be able to pull all records that is in there by the date That I have set to Sort by. Now the issue is that the Exam Fees table stores all the fees from the exams and orders them by ExamID.
Taking the ExamID and matching it up with the ExamID from the Exams table and taking that and listing all the procedures that went with this exam from the procedures table. Get it?
So if you went into the doc's and had your head examined and the doc charged $50 for the visit and $50 for the prozac you will be on, I want it to listed those items(procedures) by examID.
Get it?
So it should look like this:
Exam Date: January 1, 2003
Patient: Joe Blow
Procedures:
Head Exam
Prozac
I am also getting a Undefined Variable; ExamFee error, which is probably a typo
Now for the crazy code:
<?
require('variables.php');
?>
<?
//Get Exam Table Data
$connect = @mysql_connect($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 ExamID, PatientID, ExamDate FROM $exams WHERE ExamDate >= Date_Sub(CURDATE(), INTERVAL 8 MONTH) ORDER BY ExamDate";
$result = @mysql_query($sql, $connect) or die("Could not Execute Query #1");
While ($row = mysql_fetch_array($result)) {
$ExamID = $row['ExamID'];
$PatientID = $row['PatientID'];
$ExamDate = $row['ExamDate'];
}
?>
<?
// Get Exam Fees Table Data
$connect = @mysql_connect($dbserver, $dbuser, $dbpass) or die("Could not Connect to Server Query 2");
$db = @mysql_select_db($dbname, $connect) or die("could not select DB");
$sql = "SELECT * FROM $examfees WHERE ExamID = \"$ExamID\" ";
$result = @mysql_query($sql, $connect) or die("Could not Execute Query #2");
While ($row = mysql_fetch_array($result)) {
$ExamID2 = $row['ExamID'];
$ProcedureID = $row['ProcedureID'];
$ExamFee = $row['ExamFee'];
}
?>
<?
// Get Procedure List
$connect = @mysql_connect($dbserver, $dbuser, $dbpass) or die("Could not Connect to Server: Query 3");
$db = @mysql_select_db($dbname, $connect) or die("could not select DB");
$sql = "SELECT * FROM procedure_tbl ";
$result = @mysql_query($sql, $connect) or die("Could not Execute Query #3");
While ($row = mysql_fetch_array($result)) {
$ProcedureID2 = $row['ProcedureID'];
$Procedure = $row['ProcedureName'];
$ProcedureFee = $row['ProcedureFee'];
}
?>
<?
// Get Patient Data
$connect = @mysql_connect($dbserver, $dbuser, $dbpass) or die("Could not Connect to Server: Query 4");
$db = @mysql_select_db($dbname, $connect) or die("could not select DB");
$sql = "SELECT PatientID, PatientFirstName, PatientLastName FROM patients WHERE PatientID = \"$PatientID\" ";
$result = @mysql_query($sql, $connect) or die("Could not Execute Query #4");
While ($row = mysql_fetch_array($result)) {
$PatientID2 = $row['PatientID'];
$PatientFirstName = $row['PatientFirstName'];
$PatientLastName = $row['PatientLastName'];
}
?>
<? echo "$ExamDate"; ?><br>
<? echo "$PatientLastName, $PatientFirstName"; ?><br>
<? echo "$ProcedureID2"; ?><br>
<? echo "$ExamFee"; ?>