Forum Moderators: coopster
[edited by: theriddla1019 at 5:49 pm (utc) on Jan. 8, 2004]
$Query1 = "SELECT * FROM upininfo WHERE UPIN = '" . $Row['UPIN'] . "'";
>>Now im assuming I should be using subqueries to compile my statements but im not sure how to bring them together.
Not subqueries in this case, but a JOIN [mysql.com] statement. You could get one result set by using a single query statement such as:
$sql = "SELECT * FROM poc
INNER JOIN patientdata USING (MR)
INNER JOIN upininfo USING (UPIN)
WHERE POCID = '" . $key";
*Or how do i reference the rows from the joined tables?
Cause i need to populate the variables from the tables to distribute throughout the form that follows this php script.
modnote: see charter [webmasterworld.com] re code posts
[edited by: jatar_k at 6:10 pm (utc) on Jan. 8, 2004]
.....
$itemNumber = $HTTP_GET_VARS['itemNumber'];
if (isset($HTTP_GET_VARS['key'])) $key = $HTTP_GET_VARS['key'];
.....
require("POC_connect.php");
$Link = mysql_pconnect($Host, $User, $Password);
mysql_select_db($DBName, $Link);
if (isset($HTTP_GET_VARS['edit'])) {
$Query = "SELECT * FROM poc WHERE POCID = " . $key;
$Result = mysql_query($Query, $Link);
$Row = mysql_fetch_assoc($Result);
< 45 or so assignment statements here >
} else {
$Query = "SELECT * FROM poc " . $whereclause . $fullOrderBy . " LIMIT " . $itemNumber . ", 1";
$Result = mysql_query($Query, $Link);
$Row = mysql_fetch_assoc($Result);
$key = $Row['POCID'];
< 45 or so assignment statements here >
}
$URL = "Form485.php?key=" . $key . "&itemNumber=" . $itemNumber;
{
$Query2 = "SELECT * FROM patientdata WHERE MR = " . $MR;
$Result2 = mysql_query($Query2, $Link);
$Row2 = mysql_fetch_assoc($Result2);
< 13 or so assignment statements here >
}
{
$Query1 = "SELECT * FROM upininfo WHERE UPIN = '" . $Row['UPIN'] . "'";
$Result1 = mysql_query($Query1, $Link);
$row1 = mysql_fetch_assoc($Query1);
$PhyLast = $Row1['PhyLast'];
< 13 or so assignment statements here >
}
also in your final fetch_assoc you have the var $row1 but all of your assignments follow are using $Row1, that won't work since variables are case sensitive
I didn't see that in the original chunk of code that was there...nice catch jatar_k.
>>*Or how do i reference the rows from the joined tables?
The same way you were before. The result set will still contain all the fields named as key=>value pairs when you use mysql_fetch_assoc to process the result set. It's just that they are now in one result set as opposed to three.
$Row = mysql_fetch_assoc($Result, $Link);
$ProviderID = $Row['ProviderID'];
$MR = $Row['MR'];
{More variables populating}
}
Here is how I tend to troubleshoot SQL statements. First, use a variable to contain the entire SQL statement. Then, right before you execute the statement, exit the code and print the variable -- odds are you will be able to spot your issues quite quickly:
$sql = "Select * FROM poc,
upininfo, patientdata
WHERE poc.POCID LIKE '$key'
AND poc.MR = patientdata.MR AND poc.UPIN = upininfo.UPIN";
//exit($sql); // Uncomment this line for troubleshooting!
$result = mysql_query($sql);