Re: [PHP] Count totals (might be 0T)

2005-04-22 Thread Richard Lynch
On Thu, April 21, 2005 3:36 pm, Ryan A said:
 Hey,
 Thanks for replying.
 That means I will have to run a query per categorywhich I would like
 to
 avoid if possible as they could be
 a high amount of categories as they are user created and not defined by
 us.

?php
  /*
  category_count.inc
  Provides $CATEGORY_COUNT and $CATEGORY_SIZE variables for the application.
  */
  $query = select cno, count(*), sum(pic_size_kb) from TABLE group by
cno;
  $cat_info = mysql_query($query) or die(mysql_error());
  $CATEGORY_COUNT = array();
  $CATEGORY_SIZE = array();
  while (list($cno, $count, $size) = mysql_fetch_row($cat_info)){
$CATEGORY_COUNT[$cno] = $count;
$CATEGORY_SIZE[$cno] = $size;
  }
?

Only problem is that you could have a slight timing issue where the
select above gets done, then somebody adds a new image, and then you
display your counts, and then you display the list, and that extra image
is in the list, but not counted.

You *COULD* solve this by wrapping a transaction around the whole mess if
it's really critical, but you probably don't need it.



 Thanks,
 Ryan


 On 4/22/2005 12:08:31 AM, Drewcore ([EMAIL PROTECTED]) wrote:
 run another sql query:
 select pic_size_kb from table where
 pic_category='$current_category,
 then make a loop that increments a)

 the total number of records (ie total number of pics in category), and

 then adds the pic size from each record to some variable (eg

 $total_kb) and then you have your total.



 hope that helps.



 drew



 On 4/21/05, Ryan A [EMAIL PROTECTED] wrote:

  Hi again,

  Am faced with a new problem (either that or working straight 10 hours
 is

  catching up!)

 

  Heres my table (easy to figure out so i wont waste your time
 explaining
 the

  fields):

  cno,

  date_added,

  pic_name,

  pic_size_kb,

  pic_desc_text,

  pic_category

 

  the way i am displaying the data is like this (thanks to Phillip and
 Andy

  from this list)

 

   __

   category here



 --
 No virus found in this outgoing message.
 Checked by AVG Anti-Virus.
 Version: 7.0.308 / Virus Database: 266.10.1 - Release Date: 4/20/2005

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




-- 
Like Music?
http://l-i-e.com/artists.htm

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



[PHP] Count totals (might be 0T)

2005-04-21 Thread Ryan A
Hi again,
Am faced with a new problem (either that or working straight 10 hours is
catching up!)

Heres my table (easy to figure out so i wont waste your time explaining the
fields):
cno,
date_added,
pic_name,
pic_size_kb,
pic_desc_text,
pic_category

the way i am displaying the data is like this (thanks to Phillip and Andy
from this list)

 __
 category here   2pics, 90kb  |
 -
 | pic-here | pic_desc_text |
 | pic-here | pic_desc_text |
 __
 category here  2pics, 160kb  |
 -
 | pic-here | pic_desc_text |
 | pic-here | pic_desc_text |
 -

When I sql the DB I call it like this: select picture_name,more
 fields from table where cno=x order by category.

Any ideas as to how i get how many pics per category and size per category?
I'm not sure if its a PHP thing or a MySql thing...

Last problem for the day...then i hit the sack!
Thanks in advance,
Ryan



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.10.1 - Release Date: 4/20/2005

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



Re: [PHP] Count totals (might be 0T)

2005-04-21 Thread Ryan A
Hey,
Thanks for replying.
That means I will have to run a query per categorywhich I would like to
avoid if possible as they could be
a high amount of categories as they are user created and not defined by us.
Thanks,
Ryan


On 4/22/2005 12:08:31 AM, Drewcore ([EMAIL PROTECTED]) wrote:
 run another sql query:
 select pic_size_kb from table where
 pic_category='$current_category,
 then make a loop that increments a)

 the total number of records (ie total number of pics in category), and

 then adds the pic size from each record to some variable (eg

 $total_kb) and then you have your total.



 hope that helps.



 drew



 On 4/21/05, Ryan A [EMAIL PROTECTED] wrote:

  Hi again,

  Am faced with a new problem (either that or working straight 10 hours
 is

  catching up!)

 

  Heres my table (easy to figure out so i wont waste your time explaining
 the

  fields):

  cno,

  date_added,

  pic_name,

  pic_size_kb,

  pic_desc_text,

  pic_category

 

  the way i am displaying the data is like this (thanks to Phillip and
 Andy

  from this list)

 

   __

   category here



-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.10.1 - Release Date: 4/20/2005

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



Re: [PHP] Count totals (might be 0T)

2005-04-21 Thread Tom Rogers
Hi,

Friday, April 22, 2005, 8:03:06 AM, you wrote:
RA Hi again,
RA Am faced with a new problem (either that or working straight 10 hours is
RA catching up!)

RA Heres my table (easy to figure out so i wont waste your time explaining the
RA fields):
RA cno,
RA date_added,
RA pic_name,
RA pic_size_kb,
RA pic_desc_text,
RA pic_category

RA the way i am displaying the data is like this (thanks to Phillip and Andy
RA from this list)

RA  __
RA  category here   2pics, 90kb  |
RA  -
RA  | pic-here | pic_desc_text |
RA  | pic-here | pic_desc_text |
RA  __
RA  category here  2pics, 160kb  |
RA  -
RA  | pic-here | pic_desc_text |
RA  | pic-here | pic_desc_text |
RA  -

RA When I sql the DB I call it like this: select picture_name,more
 fields from table where cno=x order by category.

RA Any ideas as to how i get how many pics per category and size per category?
RA I'm not sure if its a PHP thing or a MySql thing...

RA Last problem for the day...then i hit the sack!
RA Thanks in advance,
RA Ryan


Something like

SELECT COUNT(pic_name) as pic_count, SUM(pic_size_kb) as pic_total
FROM pic_table GROUP BY pic_category

-- 
regards,
Tom

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



RE: [PHP] Count totals(might be 0T)

2005-04-21 Thread Chris W. Parker
Ryan A mailto:[EMAIL PROTECTED]
on Thursday, April 21, 2005 3:03 PM said:

 When I sql the DB I call it like this: select picture_name,more
  fields from table where cno=x order by category.
 
 Any ideas as to how i get how many pics per category and size per
 category? I'm not sure if its a PHP thing or a MySql thing...

By either running a query for each category grabbing the data you want.
Or by grabbing the data you want in the initial query and adding it all
up BEFORE you start to do you display logic.

So the second option would be:

1. Get all the data.
2. Loop through all the data creating the tally(s) you want.
3. Loop through the data again creating your visual gropings and
throwing in the tally(s) you created earlier.

Try both options and time them.


Chris.

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