Multi select loop design

Hi it’s me again with another question. I am need of some pointers .
I am designing an order processing system, so far I have a page showing the order details e.g. Customer details, dates and items ordered.This works via a number of selects and a loop to show all the items ordered on One page.

The next thing, which is what I can’t get my head around as yet ,is to be able to loop through the details in such a way as to be able to print a page for each item ordered. So it needs the customer details etc on each page but only one of the items ordered.

I have set up a field in the database that has 1 added to it each time an item is ordered for that session order ref.
“SELECT MAX(item_number) AS max_number FROM items WHERE order_id = ‘$order_id’”);
So this will give me a way to loop through just the items associated with that order.

If you can give me some pointers as to how I can include a number of selects within a loop to do this.

thanks Kevin.

select the customer details once, and assign them to variables so you don’t get mixed up.

$customer_id = 7 ;
$customer_name = “joe mighty”;

Then do one more select fetching all of this customers matching orders (possibly pseudo-code as “where customer_id = 7 and date = xxx”)

Loop through that result set of orders and as you do so insert the $customer_name etc in the header.

2 selects :slight_smile: no?

user join to fetch the records on the basis of order id and customer id.

For items per page you can use pagination

Yes a bit of both !!

First A4 page will be customer copy, thats what I have working all details
recipient name & address customer name address etc and items ordered all on one page.

after thats been printed then need to be able to print shop copy recipient & customer details as above but just one of the items ordered per page.
most of our orders would be two or three items per order.

Thanks for your thoughts, not sure if I did not make it clear as to what I am trying to do.
I have now got it working in a fashion but am still open to any better ideas.

In my controller script I have added

if($max_number == “1”){ //// this is the number of items added to this order ref ///
include $_SERVER[‘DOCUMENT_ROOT’] . ‘/includes/db.inc.php’;
$sql = "SELECT * FROM items WHERE order_id='$id’AND item_number=‘1’ ";
$result = mysqli_query($link, $sql);
if (!$result)
{
$error = ‘Error fetching customer from database!’;
include ‘error.html.php’;
exit();
}

while ($row = mysqli_fetch_array($result))
{
$item_code = ($row[‘item_code’]);
$item_description =($row[‘item_description’]);
$item_price=($row[‘item_price’]);
$card_message=($row[‘card_message’]);
$item_number=($row[‘item_number’]);
}
include ‘1_page.html.php’;
exit();
}
elseif($max_number == “2”){

these elseif statements then include 1 of 5 output pages.
On these pages I have all the echo’s needed to form an order page, then by copy/paste that code 1,2,3,4 or 5 times on a single page this has given me the number of printed pages needed.
This all works but the down sides are a lot of extra work making all the output pages and I am limited to say 5 items per order.
Is there a better way to get this result.

Thanks Kevin.

do you need to print each item as a separate order??

Or

print the item as per the customer ordered?