Re: Summary Report With Details - Newbie Question
| From: | revDAVE | Date: | Tue, 17 Mar 2009 00:57:13 +0000 |
| Subject: | Re: Summary Report With Details - Newbie Question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-290142@lists.php.net to get a copy of this message | ||
On 3/14/2009 9:31 PM, "Paul M Foster" <paulf@quillandmouse.com> 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?
--
Thanks - RevDave
Cool @ hosting4days . com
[db-lists 09]