[SQL]Grabbing the number of comments

Experienced Elementalist
Joined
Apr 15, 2008
Messages
256
Reaction score
0
Im trying to make the results look like:
Comments(84) where 84 would be how many records there is in the comments table where news_id is 1
PHP:
<a href="index.php?comment=<?php echo($data['ID']) ?>">Comments(
		  <?php
		   $counta=mysql_query("SELECT count(comments) FROM comments WHERE news_id='".$data['id']."'") or die(mysql_error());
		  $query=mysql_query("SELECT count(comments) FROM comments WHERE news_id='".$data['id']."'") or die(mysql_error());
		  ?></a>)
 
I don't really understand since you don't clearly state your problem.

Here's how I would do it (not really):

PHP:
<a href="index.php?comment=<?php echo($data['ID']) ?>">Comments(<?php echo mysql_result(mysql_query("SELECT COUNT(*) FROM comments WHERE news_id = '{$data['id']}'"), 0, 0) ?>)
 
Back