mysqli_fetch_array()中的警告

时间:2019-12-12 03:44:08

标签: php html mysql mysqli

为什么我的数组由于mysqli_fecth数组而出错?我可以对代码进行的处理是正确的,因为我是一个初学者。我将代码更改为mysqli_fetch_assoc(),但错误相同。

这是我编写的代码:

      <?php
      $query = mysqli_query($con,"SELECT t.po_nomor, p.nama_supplier, p1.nama_barang , t.total FROM 
        (SELECT t1.po_nomor, (SUM(t1.jumlah)-SUM(COALESCE(t4.terima,0))over(PARTITION by t4.refrence) ) as total 
        FROM pengiriman_supply t1 
        INNER JOIN data_supplier t2 ON t1.idsupplier = t2.id_supplier 
        INNER JOIN data_barang t3 ON t1.idbarang = t3.idbarang 
        LEFT JOIN masuk t4 ON t4.refrence = t1.po_nomor 
        where t1.tanggal BETWEEN date_sub(curdate(), interval 120 day) AND curdate() 
        group by t1.po_nomor,t4.po_nomor) t 
        INNER JOIN pengiriman_supply s ON s.po_nomor = t.po_nomor 
        INNER JOIN data_supplier p ON s.idsupplier = p.id_supplier 
        INNER JOIN data_barang p1 ON s.idbarang = p1.idbarang 
        GROUP BY t.po_nomor 
        ORDER by t.po_nomor DESC;");
      $no = 0;
      while($data = mysqli_fetch_array($query)){
       $no++;
       ?>
       <tr>
        <td><?= $no ?></td>
        <td><?= $data['po_nomor'] ?></td>
        <td><?= $data['nama_supplier'] ?></td>
        <td><?= $data['nama_barang'] ?></td>
        <td><?= $data['total'] ?></td>

      </tr>
      <?php
    }
    ?>   </tbody>

我可以在其中更改代码的地方。

2 个答案:

答案 0 :(得分:0)

您尝试将其粘贴到ur sql命令中,如果它不起作用,则说明内部存在错误。

SELECT t.po_nomor, p.nama_supplier, p1.nama_barang , t.total FROM 
        (SELECT t1.po_nomor, (SUM(t1.jumlah)-SUM(COALESCE(t4.terima,0))over(PARTITION by t4.refrence) ) as total 
        FROM pengiriman_supply t1 
        INNER JOIN data_supplier t2 ON t1.idsupplier = t2.id_supplier 
        INNER JOIN data_barang t3 ON t1.idbarang = t3.idbarang 
        LEFT JOIN masuk t4 ON t4.refrence = t1.po_nomor 
        where t1.tanggal BETWEEN date_sub(curdate(), interval 120 day) AND curdate() 
        group by t1.po_nomor,t4.po_nomor) t 
        INNER JOIN pengiriman_supply s ON s.po_nomor = t.po_nomor 
        INNER JOIN data_supplier p ON s.idsupplier = p.id_supplier 
        INNER JOIN data_barang p1 ON s.idbarang = p1.idbarang 
        GROUP BY t.po_nomor 
        ORDER by t.po_nomor DESC;

答案 1 :(得分:-1)

请尝试将 mysqli_fetch_array 结果类型一起使用。

我的意思是尝试:

while($data = mysqli_fetch_array($query, MYSQLI_ASSOC)){
//
}

您可以拿它here