Array/DB match counting

From: Date: Mon, 18 Dec 2000 16:50:18 +0000
Subject: Array/DB match counting
References: 1  Groups: php.db php.general 
Request: Send a blank email to php-db+get-5324@lists.php.net to get a copy of this message
Am doing a postgres list of categories... want to count and display the number of items (items in seperate table from categories) that match each category while displaying the categories to the user. Two questions: 1. Is is faster to do the below or to do another database select to parse all the items as we go through each category in the category database result... 2. Optimization of the below code? # get all item categories $resultCA=pg_exec($database,"SELECT Cat FROM ItemList ORDER BY CatID"); $CAnum=pg_numrows($resultCA); $CAcount=0; while($CAcount<$CAnum) { $CACapture[]=pg_result($resultCA,$CAcount,0); $CAcount++; } $CAresult=array_count_values($CACapture); # count items # then in wour while loop that we are displaying the categories with # not relavent but assume $Category is name of category # and $CatID is id num of Category from seperate category search echo "$Category ($CAresult[$CatID])<br>\n"; This displays perfectly what I am looking for which is: My Category (8) Next Category (10) Dave

« previous php.db (#5324) next »