0

I have a MySQL database wirh orders records and I want to generate PDF if status order is payed from all id's and I'm trying with mpdf but is generate me the files but all with the same value.

$qry = mysqli_query($dbs, "SELECT * FROM orders WHERE orderstatus='payed'");
$row = array();
while ($data = mysqli_fetch_array($qry)) {
    $row[] = $data;

    foreach ($row as $x) {
        $folder = 'facturi' . "/" . $x[0];
        if (!is_dir($folder)) {
            mkdir($folder, 0777, true);
            $file_name = "#DPL-" . $x[0] . ".pdf";
            $mpdf->WriteHTML($x[0]); // x[0] is > id, just for testing
        }
    }

    $mpdf->Output($folder . "/" . $file_name, 'F');
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
Fido
  • 37
  • 2
  • 11
  • Do you see the typo after I have formatted your code? You have a loop inside a loop. You can actually avoid the first loop if you use [`mysqli_fetch_all()`](https://www.php.net/manual/en/mysqli-result.fetch-all.php) – Dharman Jul 24 '20 at 21:01
  • Thank you @Dharman for your reply, can you show me how to fetch all ? Im new to this and im doing my best, thank you in advance. – Fido Jul 24 '20 at 21:06
  • This can help you https://stackoverflow.com/a/62734982/1839439 and this https://stackoverflow.com/questions/62100343/how-to-retrieve-all-rows-from-an-sql-table-into-an-array/62101059#62101059 and also this https://stackoverflow.com/a/60564642/1839439 – Dharman Jul 24 '20 at 21:09

0 Answers0