基本上我遇到了一个我似乎无法弄清楚的问题。我正在运行一个循环来检查数据库中的特定值并将它们显示在一个表中。除了存在重复值的事实之外,表格显示正常吗?
名为 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>';
}
}
}
}