PHP While 循环内的多个查询

我尝试在 while 循环内运行多个查询,但没有任何反应,没有显示错误,也没有显示成功。任何人都可以解释或帮助我解决这个问题吗?这是我的代码


<?php


include('config.php');

    

$sql    = 'SELECT * FROM inventory_masuk_dummy';

$query  = mysqli_query($conn, $sql);

    

while($row = mysqli_fetch_array($query)) {

        

        $jumlah = $row['jml'];

        $size = $row['size'];

        $nama_barang = $row['nama_barang'];

        $status = $row['status'];

        

        $sql2 = "UPDATE inventory_dummy SET jumlah = jumlah+$jumlah WHERE nama_barang = '$nama_barang' AND size = '$size'";

        

        $sql3 = "UPDATE inventory_masuk_dummy SET status = '2' WHERE status='1'";

        

        while($row = mysqli_fetch_array($sql2) && $row = mysqli_fetch_array($sql3)) {

    echo "Berhasil di ubah, anda akan segera dialihkan";

    }

}      

        

echo "Nothing...";

        

?>


胡说叔叔
浏览 105回答 1
1回答

沧海一幻觉

问题是您的代码不执行$sql2and $sql3,您可以使用再次执行它mysqli_query<?phpinclude('config.php');&nbsp; &nbsp;&nbsp;$sql&nbsp; &nbsp; = 'SELECT * FROM inventory_masuk_dummy';$query&nbsp; = mysqli_query($conn, $sql);&nbsp; &nbsp;&nbsp;while($row = mysqli_fetch_array($query)) {&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; $jumlah = $row['jml'];&nbsp; &nbsp; &nbsp; &nbsp; $size = $row['size'];&nbsp; &nbsp; &nbsp; &nbsp; $nama_barang = $row['nama_barang'];&nbsp; &nbsp; &nbsp; &nbsp; $status = $row['status'];&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; $sql2 = "UPDATE inventory_dummy SET jumlah = jumlah+$jumlah WHERE nama_barang = '$nama_barang' AND size = '$size'";&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; $sql3 = "UPDATE inventory_masuk_dummy SET status = '2' WHERE status='1'";&nbsp; &nbsp; &nbsp; &nbsp; if ( mysqli_query($conn, $sql2) && mysqli_query($conn, $sql3) ) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;echo "Berhasil di ubah, anda akan segera dialihkan";&nbsp; &nbsp; &nbsp; &nbsp; }}&nbsp; &nbsp; &nbsp;&nbsp;echo "Nothing...";&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
打开App,查看更多内容
随时随地看视频慕课网APP