Jump to content

SQL question, COUNT?


helraizer

Recommended Posts

Hi folks.

 

In my table I have

 

 

tblcomments

post_id

username

comment

time

user_id

 

and another

 

tbluser

user_id

username

password

email

dob

registered (date)

ip

logged_in

last_login

warned

active

key

banned

ban_date

 

each user has a chatbox, and each post is put into the tblcomments table with the user ID so the chatbox can pull the posts for that user's box.

 

On my home page I was thinking of having

 

 <?php 

$table = <<<TABLE
<table align="center">
<tr>
<td colspan="1"><b>Top chatbox with $posts posts</b></td>
</tr>
<tr>
<td>
<img src="user/$user.gif">
</td>
</tr>
<tr>
<td>
<a href="chatbox.php5?uid=$uid">Comment $user</a>
</td>
</tr>
</table> 
TABLE;

echo $table;
?>

 

Where $posts is going to be the number of posts;

$user is the username of the user_id with the most posts;

and $uid is the user_id of that user.

 

How would I structure a SQL statement to calculate which user_id in tblcomments has the most posts for it? and to pull the user_id and username from that?

 

Thanks,

Sam

 

Link to comment
https://forums.phpfreaks.com/topic/94959-sql-question-count/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.