Re: Summary Report With Details - Newbie Question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Mar 16, 2009 at 05:57:13PM -0700, revDAVE wrote:

> On 3/14/2009 9:31 PM, "Paul M Foster" <paulf@xxxxxxxxxxxxxxxxx> wrote:
> 
> >
> > I'm not an expert, but the way I normally do something like this is with
> > a join that would give name, model and condition on each row (so you
> > have a lot of duplicate fields which are the same for a series of
> > records). I make sure they're ordered properly, and then process them in
> > a loop. Something like:
> >
> > $product = '';
> > $count = 0;
> > while ($a = fetch_array()) {
> >     if ($product != $a['name']) {
> >         // do whatever for prior product
> >         // do whatever for new product
> >         // $count will be the number of a given product
> >         $product = $a['name'];
> >     }
> >     else {
> >         $count++;
> >         // print out whatever you need to
> >     }
> > }
> 
> Hi Paul - I appreciate your assistance,
> 
> 
> $product = '';
> $count = 1;
> while ($a = mysql_fetch_assoc($getall)) {
>     if ($product != $a['model']) {
> 
> 
>     echo '<br/> COUNT: '.$count.' final previous'.'<br/><br/>';
> 
>     $count = 1; // resets count for each new model
>     echo ' model: '.$a['model'].'<br/><br/>'; // model title line
>     echo $a['id'].' - condition: '.$a['loc'].' 1<br/>'; // start detail row
> list
>         $product = $a['model'];
>     }
>     else {
> 
>         $count++;
>         echo $a['id'].' - condition: '.$a['condition'].' 2 <br/>';
>     }
> }
> 
> ------------------------------
> 
> Produces something like:
> 
> COUNT: 39 (final previous)
> 
> model: MODEL 22-A
> 
> 34 - condition: good
> 33 - new
> 32 - old
> 305 - new
> 
> Etc...
> 
> ------------------------
> 
> Paul - this seems to work (if I understand you correctly...), but I would
> like to have a title line (above) say:
> 
> MODEL - 22-A - COUNT: 39
> 
> At the top ... Currently - the way I have it wants to display the *count
> BELOW* the line items - (when it's done counting) .. And I fooled with this
> line;
> 
> echo '<br/> COUNT: '.$count.' final previous'.'<br/><br/>';
> 
> Which 'sort of' shows at top - but doesn't really help the 1st item...
> 
> Q: any way to improve this?
> 

Well, I was dubious about my answer, based on the idea that someone else
might have a better way. However, it appears not.

So what I would do is probably, instead of echoing stuff immediately,
I'd just append it to a string until you're ready to output a total
line. Then output the total line, and immediately after, output the
string you accumulated while counting. Make sense? The whole point in
the first place, as I recall, was to avoid umpteen database queries. So
what you're doing is to load it all up at once and then let PHP do the
heavy work instead of the database. But the total you want is only
available after you've processed all the records for that item/model. So
if you want it to come first on screen, you'll have to "accumulate" all
your detail lines as you go. Then when the total is ready, output that
and then output all the stuff you've accumulated. I don't know any
better way to do it.

If it's still not clear, let me know.

Paul

-- 
Paul M. Foster

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux