[SQL]Grabbing the number of comments
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 Code:
<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>)
Re: [SQL]Grabbing the number of comments
I don't really understand since you don't clearly state your problem.
Here's how I would do it (not really):
PHP Code:
<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) ?>)
Re: [SQL]Grabbing the number of comments
<3 that worked just fine!
thanks :)
Re: [SQL]Grabbing the number of comments
Re: [SQL]Grabbing the number of comments
Quote:
Originally Posted by
Foxx123
mysql_num_row
Bad way of doing it. As you'd be retrieving data you don't need, which is inefficient.
Re: [SQL]Grabbing the number of comments
Re: [SQL]Grabbing the number of comments
Quote:
Originally Posted by
Foxx123
Mk, but it would work ;)
Yes it would, just in a very suboptimal way.