# Question about database rows

**URL:** https://forum.kirupa.com/t/question-about-database-rows/305231
**Category:** programming
**Created:** [February 21, 2010, 11:39pm UTC](https://forum.kirupa.com/t/question-about-database-rows/305231 "2010-02-21T23:39:52Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![drummer392](https://avatars.discourse-cdn.com/v4/letter/d/45deac/32.png) [@drummer392](https://forum.kirupa.com/u/drummer392)
#### Post date: [February 21, 2010, 11:39pm UTC](https://forum.kirupa.com/t/question-about-database-rows/305231/1 "2010-02-21T23:39:52Z")

</div>

I have this code, and what I am attempting to do is count rows in a table. What isn’t working, is if there aren’t any rows in the table, then it won’t return as “0”. How can I do that?

```php

$getcomments = mysql_query("SELECT * FROM `comments` WHERE `blog_id` = '".$blog['id']."'");
    while ($comments = mysql_fetch_assoc($getcomments))
	{
	if ($comments['blog_id'] == 0) {
	$num_comments = "0";
	} else {
	$num_comments = mysql_num_rows($getcomments); 
	}
	echo "<span class='comments'>$num_comments COMMENTS</span><br>";
	}

```
