You are here: Re: [PHP] Count totals (might be 0T) « PHP « IT news, forums, messages
Re: [PHP] Count totals (might be 0T)

Posted by Richard Lynch on 04/22/05 12:02

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 category....which 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 (drewsph@gmail.com) 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 <ryan@coinpass.com> 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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация