Page 1 of 1

[Solved] Counting Rows

Posted: Tue Sep 08, 2009 11:27 am
by techkid
Suppose If I want count all rows in Discussion table I'm using this code:

Code: Select all

$q = 'SELECT count(*) FROM `discussions`';
$r = $db->query($q);
$d = $r->fetch_row();
$comment_count = $d[0];

Code: Select all

<?php echo $comment_count;?>
I have a field called comment_approved, How can i count all the rows with the entry 1 in comment_approved field?
Image

Re: Counting Rows

Posted: Tue Sep 08, 2009 11:40 am
by Mirge
$q = 'SELECT count(*) FROM `discussions` WHERE comment_approved='1'';

Re: Counting Rows

Posted: Tue Sep 08, 2009 10:02 pm
by techkid
Thank you

Code: Select all

$q = 'SELECT count(*) FROM `discussions` WHERE comment_approved=1 ';

Re: [Solved] Counting Rows

Posted: Tue Sep 08, 2009 10:17 pm
by Mirge
No problem.