PDA

View Full Version : MySQL Count Rows


PaulSonny
10 Apr 2008, 05:05
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
10 Apr 2008, 06:42
Just use the mysql count function.


select count(*) from table

or

select count(*) from table where foo=bar

PaulSonny
10 Apr 2008, 11:22
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
10 Apr 2008, 12:49
You need to loop the results to find the value, alternatively, do this instead:


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

PaulSonny
10 Apr 2008, 13:02
You need to loop the results to find the value, alternatively, do this instead:


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



Worked an absolute treat, thanks all for help :)

Thanks, Paul.