1

why my array get error because mysqli_fecth array? what I can do to the code to make is true because I'm a beginner of this. I change my code to mysqli_fetch_assoc() but the error is the same.

this is the code that i make:

      <?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>

where I can change my code.

  • Can you show the error message? – quachtinh761 Dec 12 '19 at 03:56
  • the error message is like this `Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\admin2\content\masuk.php on line 72` – abdul kadir almasyhur Dec 12 '19 at 04:01
  • Ah, got the message. May your query is not correctly. Please check again. You can run the query on SQL section in phpmyadmin. Alternatively, you can check $query before get fetch data. – quachtinh761 Dec 12 '19 at 04:09
  • what I can change in my SQL query? – abdul kadir almasyhur Dec 12 '19 at 04:12
  • @TinhNV the error in query SQL is in over(partition by) what I can change that – abdul kadir almasyhur Dec 12 '19 at 04:15
  • Does this answer your question? [mysqli\_fetch\_assoc() expects parameter / Call to a member function bind\_param() errors. How to get the actual mysql error and fix it?](https://stackoverflow.com/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param) – Dharman Dec 12 '19 at 07:15

2 Answers2

0

You try to paste this in ur sql command, if it is not working, then there something wrong inside here.

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;
Zendie
  • 1,176
  • 1
  • 13
  • 30
Jt Tan
  • 175
  • 3
  • 12
-1

Please try to use mysqli_fetch_array with resulttype.

I mean try this:

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

You can take it here

quachtinh761
  • 224
  • 1
  • 7