Need to repeat MySQL query results X number of times - Returns "Line Item" Need to echo per Quantity Count

Query pulls records from 5 db tables and returns Account Receivable by line item (e.g. First Name || Last Name || Company || Product Part Number || Line Item QUANTITY

EXAMPLE OF OUTPUT:
++++++++++++++++++++++++++++++++++++++++++
Bill Smith - AJAX Inc.
p/n: 123-X555 10 EA
++++++++++++++++++++++++++++++++++++++++++
I am working on a routine to print labels and need to output something similar to:

++++++++++++++++++++++++++++++++++++++++++
Bill Smith - AJAX, Inc.
p/n: 123-X555 1 of 10
++++++++++++++++++++++++++++++++++++++++++
Bill Smith - AJAX, Inc.
p/n: 123-X555 2 of 10
++++++++++++++++++++++++++++++++++++++++++
Bill Smith - AJAX, Inc.
p/n: 123-X555 3 of 10
++++++++++++++++++++++++++++++++++++++++++
And So On...can't get this to output right...I must be missing something.

Some but not all queries will have more than one line item. So, My SELECT/WHILE statements are pulling correctly, I've just not nailed how to get an echo per "Quantity" count

Thanks!

PS - I've not added a snippet because (for one its actually rather confusing) but mainly because I know its got to be a modification to the while loop and I'm hoping someone can give me this in principle or at least cite a ref and I'll look it up.
LVL 1
RapturerAsked:
Who is Participating?
 
Roger BaklundConnect With a Mentor Commented:
Try something like this:
foreach($dataset as $row) {
  for($counter=1;$counter<=$row['Quantity'];$counter++) {
    echo $row['First'].' '.$row['Last'].' - '.$row['Company']."\n" 
         'p/n:'.$row['PartNbr'].' '.$counter.' of '.$row['Quantity']."\n";
  }
}

Open in new window

0
 
RapturerAuthor Commented:
Thank you CXR - I'll fire it up now and get back!

-Rapturer
0
 
Roger BaklundConnect With a Mentor Commented:
I answered the question:

for($counter=1;$counter<=$row['Quantity'];$counter++)

You got the same answer in question 23810852, this from  angellll:

$quantity = $therecord["quantity"];
for ($loop_quantity=1, $loop_quantity <= $quantity, $loop_quantity++)

... and this from nahime, which you accepted:

for ($i = 1; $i <= $therecord["quantity"]; $i++)

I gave the correct answer first.
0
 
RapturerAuthor Commented:
I dont wish to argue...however Nahime's answer was the most complete...he provided the entire function. My first question did not include the code snippet hence the fault is largely mine. Awarding points.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.