而mysqli_fetch_assoc不会返回第一个结果

时间:2013-06-09 13:32:07

标签: php sql

这个循环永远不会返回第一个值,尽管它会毫无问题地返回所有其他值。

while ($row3 = mysqli_fetch_assoc($result2)) {
$item_ajdi = $row3["itemId"];
$result3 = mysqli_query($con,"SELECT * FROM products WHERE id='$item_ajdi'");
$row4 = mysqli_fetch_array($result3);
$price = $row4['price'] * $row3['itemCount'];
$baf = $baf."<div class=\"kosik_item\">
    <a href=\"http://".$_SERVER['HTTP_HOST'].$row4['link']."\" style=\"color:       #bbbdbf\">  
      <img height=\"59\" src=\"./img/products/".$row4['link_image'].".jpg\" style=\"float: left; margin: 3px 30px 3px 30px\" />
      <div style=\"float: left\">".$row4['name']."</div>
    </a>
    <div style=\"float: right; margin-right: 21px; width: 12px; height: 12px; margin-top: 26px; background: red\"></div>
    <div style=\"float: right; margin-right: 21px; color: black\">€ ".$price."</div>
    <div style=\"float: right; margin-right: 18px; color: black\">".$row3['itemCount']." X</div>
    <div style=\"float: right; margin-right: 28px\">".$row4['katalogovy_kod']."</div>
    </div>";   }

1 个答案:

答案 0 :(得分:1)

您正在

中使用mysqli_fetch_array
$row4 = mysqli_fetch_array($result3);

相反,你应该使用mysqli_fetch_assoc所以

$row4 = mysqli_fetch_assoc($result3);