基本的に、私は理解できないように見えるちょっとした問題に遭遇しました。データベースで特定の値をチェックし、それらをテーブルに表示するループを実行しています。重複した値があるという事実を除けば、テーブルは正常に表示されますか?
IR_Logs という名前のメイン テーブルには、以下のコードの結合テーブルとして使用される 2 つの行しか含まれていません。
$SQL = "SELECT ID, ItemID FROM IR_Logs";
$data = $db->getResults($SQL);
$count = mysql_num_rows($data);
echo '<p>Returned Results: '.$count.'</p>';
while($row = mysql_fetch_array($data)){
$ItemID = $row[1];
$LocationID = $db->getValue("SELECT LocationID FROM IR_Logs WHERE ItemID = $ItemID");
$SQL = "SELECT SiteManager, CompanyID, Reference FROM Customer_Sites WHERE Customer_Sites.ID = $LocationID";
$LocationData = $db->getResults($SQL);
while($row2= mysql_fetch_array($LocationData)){
$SiteManagerID = $row2[0];
$CompanyID = $row2[1];
$SiteReference = $row2[2];
$SQL = "SELECT Name, Telephone, Email FROM Customer_Users WHERE CompanyID = $CompanyID AND ID = $SiteManagerID";
$ManagerData = $db->getResults($SQL);
while($row3 = mysql_fetch_array($ManagerData))
{
$Manager_Name = $row3[0];
$Manager_Telephone = $row3[1];
$Manager_Email = $row3[2];
$SQL = "SELECT (SELECT Reference FROM Inventory WHERE ID = ItemID), (SELECT Company FROM Customer_Accounts WHERE ID = CompanyID), (SELECT Reference FROM Customer_Sites WHERE ID = LocationID), Type, DATE_FORMAT(Date, '%d %M %Y'), CompanyID, LocationID FROM IR_Logs WHERE LocationID = $LocationID ORDER BY CompanyID ASC";
$LogData = $db->getResults($SQL);
if(mysql_num_rows($LogData) <> 0){
$HQEmail = $db->getValue("SELECT PrimaryEmail FROM Customer_Accounts WHERE ID = $CompanyID");
$message .= '<h3>Site Ref: '.$SiteReference.'</h3>';
$message .= '<p>For the Attention of '.$Manager_Name.', in regards to Site Reference: '.$SiteReference.'</p>';
$message .= $blk->GetBlock(6);
$message .= '<table style="border:1px solid black; padding: 10px;" cellpadding="10">';
$message .= '<tr>';
$message .= '<td><strong>Reference</strong></td>';
$message .= '<td><strong>Type</strong></td>';
$message .= '<td><strong>Date</strong></td>';
$message .= '</tr>';
while($row4 = mysql_fetch_array($LogData)){
$Reference = $row4[0];
$Location = $row4[2];
$Company = $row4[1];
$Type = $row4[3];
$Date = $row4[4];
$CompanyID = $row4[5];
$LocationID= $row4[6];
$message .= '<tr>';
$message .= '<td>'.$Reference.'</td>';
$message .= '<td>'.$Type.'</td>';
$message .= '<td>'.$Date.'</td>';
$message .= '</tr>';
}
$message .= '</table>';
}
}
}
}