doujiu5464 2017-01-13 02:31
浏览 46
已采纳

while循环在第一个循环停止,因为mysqli错误

the error reads

mysqli_fetch_array() expects parameter 1 to be mysqli_result, double given in C:\xampp\htdocs\beta\jawa\isi.php on line 744

line 744 is : while($r=mysqli_fetch_array($hasil))

the full code :

<?php
$cari = "SELECT * FROM produk WHERE " ;
for ($i=0; $i<=$jml_kata; $i++) {
    $cari .= "deskripsi LIKE '%$pisah_kata[$i]%' OR nama_produk LIKE '%$pisah_kata[$i]%'";
    if ($i < $jml_kata ) {
        $cari .= " OR "; 
    }
}

$cari .= " ORDER BY id_produk DESC LIMIT 12";
$hasil  = mysqli_query($con,$cari);

while($r=mysqli_fetch_array($hasil)) {

    include "diskon_stok.php";
    echo"<div class='container_produk'>
        <a href='produk-$r[id_produk]-$r[produk_seo].html'><img src='http://images.rajafotocopy.com/foto_produk/$r[gambar]'/></a>
        <div class='detail'> 
            <span style='font-family : sui'>$r[nama_produk]</span><br />
            $divharga
        </div>
    </div>";
}
?>

I don't understand what's wrong with mysqli_result....? it is returning the 1st loop but after that it throws an error and expects parameter 1 to be mysqli_result?

  • 写回答

2条回答 默认 最新

  • dongmen5867 2017-01-13 02:48
    关注

    Something in diskon_stok.php is doing:

    $hasil = <something>;
    

    where <something> is a number.

    So when the loop repeats and it calls mysqli_fetch_array($hasil), the variable no longer contains the query result, it contains this number, and that call fails.

    Change the name of the variable you're using for the query result.

    $result  = mysqli_query($con,$cari);
    
    while($r=mysqli_fetch_array($result)){
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作