我正在进行查询并使用fetch_assoc()获取结果,问题就在里面,在我用第一个查询的结果做另一个查询,然后我做一个If语句来检查是否有结果,它应该输入if ONCE,但由于某种原因,它进入两次,我无法搞清楚。这是代码。
$query = "SELECT IDS,fecha_finalizacion,hora_finalizacion FROM subastas WHERE IDS NOT IN (SELECT IDS FROM subastas_finalizadas) AND Finalizada='S'";
if ($result = $db->query($query)) {
while ($row = $result->fetch_assoc()) {
$pujaNC = $db->query("Select IDS,ID_puja,fecha_noconfirm,hora_noconfirm FROM pujas_noconfirm WHERE IDS=" . $row['IDS'] ." ORDER BY monto asc limit 1");
while ($rowPNC = $pujaNC->fetch_assoc()) {
$infoPNC=$rowPNC;
}
if($infoPNC){
echo "BIDNC: ".$infoPNC['IDS']." ".$infoPNC['ID_puja']." <br/>";
}
}
}
它应显示BIDNC:35 107然后BIDNC为空。
答案 0 :(得分:0)
认为你需要移动你的if条件
if ($result = $db->query($query)) {
while ($row = $result->fetch_assoc()) {
$pujaNC = $db->query("Select IDS,ID_puja,fecha_noconfirm,hora_noconfirm FROM pujas_noconfirm WHERE IDS=" . $row['IDS'] ." ORDER BY monto asc limit 1");
while ($rowPNC = $pujaNC->fetch_assoc()) {
$infoPNC=$rowPNC;
}
}
if($infoPNC){
echo "BIDNC: ".$infoPNC['IDS']." ".$infoPNC['ID_puja']." <br/>";
}
}