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

Posted on 2008-10-12
Last Modified: 2013-12-13
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

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


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.
Question by:Rapturer
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 39

Accepted Solution

Roger Baklund earned 500 total points
ID: 22699113
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


Author Comment

ID: 22699130
Thank you CXR - I'll fire it up now and get back!

LVL 39

Assisted Solution

by:Roger Baklund
Roger Baklund earned 500 total points
ID: 22709730
I answered the question:


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.

Author Closing Comment

ID: 31505496
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.

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question