prepare(" -6ren">
gpt4 book ai didi

php - 数据在网页上显示两次,但数据库中没有重复项。为什么?

转载 作者:行者123 更新时间:2023-11-29 23:21:14 25 4
gpt4 key购买 nike

我试图找出为什么我的数据在我的网页上显示两次,但数据库中没有两个相同的条目。这是我正在使用的代码。

$truckDueList = "";

$sTruckDue = $dbh->prepare("
SELECT idTruck, truckNumber, status
FROM Truck
WHERE Truck.id_divisions = :idDivision
");
$sTruckDue->bindValue(":idDivision", $_SESSION['division']);
if ($sTruckDue->execute()) {
while($rowTruck = $sTruckDue->fetch()){
$dueList = "";
$more = false;
$workNeeded = false;

$sTruckAlertType = $dbh->query("
SELECT idTruckAlertType, description
FROM TruckAlertType
");
while($sTruckAlertType && $row = $sTruckAlertType->fetch()){

$sTruckAlert = $dbh->prepare("
SELECT truckAlerts.idTruck, truckAlerts.flag
FROM `truckAlerts`, Truck
WHERE Truck.status != 'inactive'
AND truckAlerts.idTruck = :idTruck
AND truckAlerts.idTruck = Truck.idTruck
AND truckAlerts.idTruckAlertType = :idTruckAlertType
AND truckAlerts.flag > 0
");
$sTruckAlert->bindValue(":idTruck", $rowTruck['idTruck']);
$sTruckAlert->bindValue(":idTruckAlertType", $row['idTruckAlertType']);
$sTruckAlert->execute();
$workNeedRow = $sTruckAlert->fetch();
if(isset($workNeedRow['idTruck'])) {
$workNeeded = true;
if ($more == true){
$dueList .= ", ";
}
$more = true;
$dueList .= "<span class='notice_level_" . $workNeedRow['flag'] . "'>" . $row['description'] . "</span>";
}
if($workNeeded == true){
$truckDueList .= "
<tr style='cursor:pointer;' onclick=\"DoNav('vehicleDetails.php?tid=" . $rowTruck['idTruck'] . "');\">
<td width='20%' class='rightSide'>" . $rowTruck['truckNumber'] . "</td>
<td class='rightSide leftSide'>" . $dueList . "</td>
<td width='15%' class='leftSide'>" . ucfirst($rowTruck['status']) . "</td>
</tr>
";
}
}
$sTruckAlertType->closeCursor();
}
$sTruckDue->closeCursor();
}

if($truckDueList == ""){
$truckDueList = "
<tr>
<td colspan='3'>No Vehicles Due</td>
</tr>";
}

我无法发布所显示内容的图像,但它看起来像这样:

ID:所需工作:

100次换油

100 次换油、轮胎换位

由于某种原因,它显示额外的机油更换,但仅在更换机油时才显示。不重复轮胎轮换。我已经检查并重新检查了数据库,没有重复的条目,但似乎显示好像有。知道为什么吗?

最佳答案

移动整个 block :

if($workNeeded == true){    
$truckDueList .= "
<tr style='cursor:pointer;' onclick=\"DoNav('vehicleDetails.php?tid=" . $rowTruck['idTruck'] . "');\">
<td width='20%' class='rightSide'>" . $rowTruck['truckNumber'] . "</td>
<td class='rightSide leftSide'>" . $dueList . "</td>
<td width='15%' class='leftSide'>" . ucfirst($rowTruck['status']) . "</td>
</tr>
";
}

紧接在 $sTruckAlertType->closeCursor(); 之后 — 它绝对应该与重置所有本地变量处于同一嵌套级别($dueList 等)

目前,您在每个 $sTruckAlertType->fetch() 上输出此内容。

关于php - 数据在网页上显示两次,但数据库中没有重复项。为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27276854/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com