Solved

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

Posted on 2008-10-12
4
825 Views
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

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.
0
Comment
Question by:Rapturer
  • 2
  • 2
4 Comments
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 500 total points
Comment Utility
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
 
LVL 1

Author Comment

by:Rapturer
Comment Utility
Thank you CXR - I'll fire it up now and get back!

-Rapturer
0
 
LVL 39

Assisted Solution

by:Roger Baklund
Roger Baklund earned 500 total points
Comment Utility
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
 
LVL 1

Author Closing Comment

by:Rapturer
Comment Utility
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

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now