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
Share on other sites

Ah, I see why that's confusing, but they're not the same.

 

username in tbluser is the registered username for the user

 

and

 

username in tblcomments is the username of the person posting the comment, it's user submitted, so could be anything.

 

Sam

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.