Need some PHP/MySQL help - "number of post list"
Posted: Mon Apr 13, 2009 9:20 pm
I've got a table with lots of comments. There are four fields - id, parent, comment and author.
Now, I want to list all authors like this:
Author - Number of comments
-----------------------------
Author1 - 10
Author2 - 3
Author3 - 23
-----------------------------
I tried to do it like this:But it didn't work out as planned. It didn't show anything but the rows above the php code, but when I removed the second td in the while loop, it listed up all authors. So I'm wondering how I can solve this.
Thanks.
Now, I want to list all authors like this:
Author - Number of comments
-----------------------------
Author1 - 10
Author2 - 3
Author3 - 23
-----------------------------
I tried to do it like this:
Code: Select all
<table>
<tr>
<td><strong>Author</strong></td>
<td><strong>Number of comments</strong></td>
</tr>
<?php
mysql_connect('xxx','xxx','xxx') or die("mysql error");
mysql_select_db("xx") or die("mysql error");
$all = mysql_query("SELECT author FROM comments");
while($fetch = mysql_fetch_array($cs_all)) {?>
<tr>
<td><strong><?php echo $fetch['author']; ?></strong></td>
<td><?php echo mysql_num_rows(mysql_query("SELECT author FROM comments WHERE author='".$fetch['author']."'")); ?></td>
</tr>
<?php }?>
</table>Thanks.