Re: array count()

From: Date: Tue, 11 Jul 2000 11:35:28 +0000
Subject: Re: array count()
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-5897@lists.php.net to get a copy of this message
I think this will do what you want, but I don't know if the performance will be any better than doing seven queries. You could probably change the ifs for a switch case statement >What I really want to do is count how many >records are in the db table that are in a catagory. I have 7 catagories and >want to return a count of each without making 7 queries. $count = 0; $cat1 = 0; $cat2 = 0; $arrResult = array(); while ( $row = mysql_fetch_array($result)) { $arrResult[$count] = $row; if (($arrResult[$count]["cat_field"]) == "cat1"){ $cat1++; } else if (($arrResult[$count]["cat_field"]) == "cat2"){ $cat2++; } $count++; } mysql_free_result($result); echo "there are $cat1 cat1s, $cat2 cat2s making a total of $count records"; ----------------------------------------------------------------- Lez Lytollis - Internet Developer Computer Clothing Research Ltd. www.computerclothingresearch.co.uk

« previous php.general (#5897) next »