PDA

View Full Version : Better way to get count


Lionel
17 Feb 2007, 03:51
What is a better way to get the count in below query? The code in the foreach loop is killing me. I am trying to get the number of threads with same threadprefix


$getcount=$db->query_first("SELECT count(*) as tot from ".TABLE_PREFIX."thread WHERE threadprefix='$threadprefix'");
$tot = number_format($getcount['tot']);



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------

Cap'n Steve
17 Feb 2007, 07:37
I think you want to look into the "GROUP BY" syntax. Try somthing like this:



Code:
---------------
Code is only visible to licensed users, and only when logged into the forums.
---------------

Lionel
17 Feb 2007, 15:29
Thanks, but still no luck

Looks like there is no other way to get that count. Unfortunately this adds a lot of queries when in foreach loop and page takes a long time to load.