[Solved] Counting Rows

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
techkid
Forum Commoner
Posts: 54
Joined: Sat Sep 05, 2009 11:18 pm
Location: Maldives

[Solved] Counting Rows

Post 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
Last edited by techkid on Tue Sep 08, 2009 10:04 pm, edited 1 time in total.
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: Counting Rows

Post by Mirge »

$q = 'SELECT count(*) FROM `discussions` WHERE comment_approved='1'';
User avatar
techkid
Forum Commoner
Posts: 54
Joined: Sat Sep 05, 2009 11:18 pm
Location: Maldives

Re: Counting Rows

Post by techkid »

Thank you

Code: Select all

$q = 'SELECT count(*) FROM `discussions` WHERE comment_approved=1 ';
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: [Solved] Counting Rows

Post by Mirge »

No problem.
Post Reply