Re: [PHP] Summary Report With Details - Newbie Question

2009-03-16 Thread revDAVE
On 3/14/2009 9:31 PM, Paul M Foster pa...@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'].' 1br/'; // 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]




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



Re: [PHP] Summary Report With Details - Newbie Question

2009-03-16 Thread Paul M Foster
On Mon, Mar 16, 2009 at 05:57:13PM -0700, revDAVE wrote:

 On 3/14/2009 9:31 PM, Paul M Foster pa...@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'].' 1br/'; // 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



Re: [PHP] Summary Report With Details - Newbie Question

2009-03-16 Thread revDAVE
On 3/16/2009 7:17 PM, Paul M Foster pa...@quillandmouse.com wrote:

 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.


Thanks for your help PAUL - with your explanation I got it working - Yipee!!

Like this 

==

$product = '';
$productlast = '';
$show='';
$count = 1;
while ($a = mysql_fetch_assoc($getall)) {
if ($product != $a['model']) {

 if ($productlast != '') {
echo 'br/br/br/MODEL: '.$productlast.' TOTAL COUNT '.$count.'
br/br/ '.$show;}

$show='';
$count = 1; // resets count for each new model
$product = $a['model'];
$show = $show . $a['model'].' '.$a['id'].' - loc:
'.$a['condition'].' 1br/';


}
else {
$count++;
$productlast = $a['model'];
$show = $show .  $a['model'].' '.$a['id'].' - loc '.$a['
condition'].' 2 br/';
}
}



--
Thanks - RevDave
Cool @ hosting4days . com
[db-lists 09]




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



Re: [PHP] Summary Report With Details - Newbie Question

2009-03-14 Thread Paul M Foster
On Fri, Mar 13, 2009 at 03:29:00PM -0700, revDAVE wrote:

 Hi Folks,
 
 I would like to make a summary report with details for a products inventory
 list - so it could list:
 
 A - the product  a few summaries like total count on 1 line
 B - --- below that: the details of a multi line sub list with inventory
 data like:
 
 A - PRODUCT #1 - count = 25
 B -- id 56 - condition = good
  id 98 - condition = new
 A - PRODUCT #2 - count = 18
 B -- id 205 - condition = new
  id 381 - condition = poor
 
 and repeat for all inventory products
 
 -
 
 The way I'm doing it now is :
 
 main query #1
 
 SELECT name,model, count(prid) as thecount FROM inventory group by model
 
 then do a repeat region table to display 1 of each
 
 - then - on each row - do sub query#2 :
 
 SELECT name,model, condition (etc) FROM inventory where model =
 quety#1.model
 
 - then display these details in a sub table
 
 
 Q: This seems to work fine. I was just wondering if there is a better way to
 construct queries to get the same result?
 
 
 Thanks in advance for your help...

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

If anyone knows a better way to do this with just SQL, I'm interested.

Paul

-- 
Paul M. Foster

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