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
844 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
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

0
 
LVL 1

Author Comment

by:Rapturer
ID: 22699130
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
ID: 22709730
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
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.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Which userID to use for shopping cart application 13 27
Get a subdirectory name from a url 5 27
MVC - procedural PHP 10 35
PHP Echo with auto submit 8 28
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

856 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