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

时间:2014-12-03 16:32:22

标签: php mysql

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

$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换油,轮胎旋转

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

1 个答案:

答案 0 :(得分:0)

移动整个区块:

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()输出一次。