How to modify php script to print html table “X” times based on the value in a n

HI everyone I am new here and would really appreciate any help offered!

I have a simple PHP script which queries my mysql database and outputs an html table. I would like to modify this script to output the table “x” number of times based on a field in the database called “quantity”. Basically it is printing shipping labels and they may have ordered 6 boxes so I need 6 labels. Does this make sense?

[php]<?php
$q = intval($_GET[‘q’]);

$con = mysqli_connect(‘’,'’,'’,'****’);
if (!$con) {
die('Could not connect: ’ . mysqli_error($con));
}

mysqli_select_db($con,“db116223_wmi”);
$sql=“SELECT * FROM tbl_purchase_order WHERE purchase_order_id = '”.$q."’";
$result = mysqli_query($con,$sql);

while($row = mysqli_fetch_array($result)) {
echo “

”;
echo “”;
echo “”;
echo “”;
echo “";
echo “”;
echo “”;
echo “”;
echo “”;
echo “”;
echo “
434 Williams Street, Suite 310
Cobuurg Ontario K9A 4X7
(905) 373-0735 Fax (905) 373-0735
To:>>>>>>>
PO:”. $row[‘po_number’] .“
Total Boxes:”. $row[‘product_quantity’] .“
Box 1 of 6
”. $row[‘first_name’] ."". $row[‘last_name’] ."
". $row[‘shipping_address’] ."
". $row[‘shipping_city’] ."". $row[‘shipping_state_province’] ."
". $row[‘shipping_phone’] .“
ZIP CODE >>”. $row[‘shipping_postal_code’] ."
”;
}

mysqli_close($con);
?>[/php]

[php] while($row = mysqli_fetch_array($result)) {
for ($x=0; $x < $row[‘product_quantity’]; $x++) {
echo “

”;
echo “”;
echo “”;
echo “”;
echo “";
echo “”;
echo “”;
echo “”;
echo “”;
echo “”;
echo “
434 Williams Street, Suite 310
Cobuurg Ontario K9A 4X7
(905) 373-0735 Fax (905) 373-0735
To:>>>>>>>
PO:”. $row[‘po_number’] .“
Total Boxes: " . ( $x + 1 ) . " of " . $row[‘product_quantity’] . “
”. $row[‘first_name’] .”". $row[‘last_name’] ."
". $row[‘shipping_address’] ."
". $row[‘shipping_city’] ."". $row[‘shipping_state_province’] ."
". $row[‘shipping_phone’] .“
ZIP CODE >>”. $row[‘shipping_postal_code’] ."
”;
}
}[/php]

This is untested, but maybe something like this?

Sponsor our Newsletter | Privacy Policy | Terms of Service