View Full Version : MySQL Count Rows
PaulSonny
04-10-2008, 03:05 AM
Hello Everybody,
I think i'm looking around the right area but struggling and would really appreciate any help.
Basically, I'm want to count how many 'rows' I have in my DB table and then display that figure in the AdminCP like Total: $totalrows.
I also want to be able to put a SQL constraint in, for example count how many 'rows' for id=0.
Any help?
Thanks, Paul.
Eikinskjaldi
04-10-2008, 04:42 AM
Just use the mysql count function.
select count(*) from table
or
select count(*) from table where foo=bar
PaulSonny
04-10-2008, 09:22 AM
This seems like a really noob error but I cant get it working.
I have this SQL statement:
$counttotalproduct = $vbulletin->db->query_read("SELECT COUNT(*) FROM " . TABLE_PREFIX . "cart_product");
then I have this line to show the result?
Total Products: $counttotalproduct
But its showing up as:
Total Products: Resource id #17
Any help?
Thanks, Paul.
Dismounted
04-10-2008, 10:49 AM
You need to loop the results to find the value, alternatively, do this instead:
$counttotalproduct = $vbulletin->db->query_first("SELECT COUNT(*) AS countrows FROM " . TABLE_PREFIX . "cart_product");
$counttotalproduct = $counttotalproduct['countrows'];
PaulSonny
04-10-2008, 11:02 AM
You need to loop the results to find the value, alternatively, do this instead:
$counttotalproduct = $vbulletin->db->query_first("SELECT COUNT(*) AS countrows FROM " . TABLE_PREFIX . "cart_product");
$counttotalproduct = $counttotalproduct['countrows'];
Worked an absolute treat, thanks all for help :)
Thanks, Paul.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.