Nested while only returning 1 result
Posted: Wed Aug 04, 2010 8:41 pm
I'm trying to pull data from a SQL table that match a certain criteria and if true, I want it to pull associated info from another table. I am using while loops and I got it to work, but it only pulls out the 1st result. I know I am missing something. Any help would be appreciated. It's been a while since I worked with PHP/MySQL. Here's the code. Thanks.
/* Get General Information */
$Res = "SELECT * FROM general"; $Results = mysql_query($Res) or die ('Could Not Access general Table: ');
/* Get Purchasing Information */
$Res_pur = "SELECT * FROM Purchasing WHERE Date BETWEEN '$beg_date' AND '$end_date'";
$Results_pur = mysql_query($Res_pur)or die('Could Not Access Purchasing Table: ' . mysql_error());
while ($Results_pur_Arr = mysql_fetch_array($Results_pur)) {
while ($Results_Arr = mysql_fetch_array($Results)) {
if ($Results_pur_Arr['ID'] == $Results_Arr['ID']) {
echo '<tr><td>'. $Results_pur_Arr['Date'].'</td><td>'. $Results_Arr['ID'].'</td><td>'.$Results_Arr['LName'].'</td><td>'.$Results_Arr['FName'].'</td>
<td>'.$Results_Arr['Address'].'</td><td>'.$Results_Arr['City'].'</tr>';
}}}
/* Get General Information */
$Res = "SELECT * FROM general"; $Results = mysql_query($Res) or die ('Could Not Access general Table: ');
/* Get Purchasing Information */
$Res_pur = "SELECT * FROM Purchasing WHERE Date BETWEEN '$beg_date' AND '$end_date'";
$Results_pur = mysql_query($Res_pur)or die('Could Not Access Purchasing Table: ' . mysql_error());
while ($Results_pur_Arr = mysql_fetch_array($Results_pur)) {
while ($Results_Arr = mysql_fetch_array($Results)) {
if ($Results_pur_Arr['ID'] == $Results_Arr['ID']) {
echo '<tr><td>'. $Results_pur_Arr['Date'].'</td><td>'. $Results_Arr['ID'].'</td><td>'.$Results_Arr['LName'].'</td><td>'.$Results_Arr['FName'].'</td>
<td>'.$Results_Arr['Address'].'</td><td>'.$Results_Arr['City'].'</tr>';
}}}