Jump to content

Find biggest poster


verdrm

Recommended Posts

Use an associative array to tally the records, then reverse sort the array while preserving the keys.

 

$userposts=array();

$result=mysql_query ('select `username` from `table`');

while ($row = mysql_fetch_assoc($result)) $userposts[$row['username']]++;

arsort($userposts);

list($user, $count) = each($userposts);

Link to comment
https://forums.phpfreaks.com/topic/162419-find-biggest-poster/#findComment-857395
Share on other sites

Use an associative array to tally the records, then reverse sort the array while preserving the keys.

 

$userposts=array();

$result=mysql_query ('select `username` from `table`');

while ($row = mysql_fetch_assoc($result)) $userposts[$row['username']]++;

arsort($userposts);

list($user, $count) = each($userposts);

 

That's the most inefficient way to solve this problem.  Why have MySQL return ALL the records when you only need 1...  What if there's 80,000 users, are you going to put them in an array?

Link to comment
https://forums.phpfreaks.com/topic/162419-find-biggest-poster/#findComment-857396
Share on other sites

That's the most inefficient way to solve this problem.  Why have MySQL return ALL the records when you only need 1...  What if there's 80,000 users, are you going to put them in an array?

 

Which 1 record contains the tally? Why do you assume that the 'post' field is a count of all posts made, rather than the post itself?

 

Why would verdrm be asking how to find the biggest poster if it was a simple matter of sorting by the 'post' field?

 

I stated to only pull the 'username' field because of efficiency. There is no need to pull the content when you are only interested in the count.

 

This is a PHP problem, not a MySQL problem.

Link to comment
https://forums.phpfreaks.com/topic/162419-find-biggest-poster/#findComment-857483
Share on other sites

Which 1 record contains the tally?

 

I don't know, that's why I said, "Assuming 'post' is number of total posts.".

 

Why do you assume that the 'post' field is a count of all posts made, rather than the post itself?

 

Same reason you assumed otherwise.  Because the OP didn't specify, it doesn't matter anyway, you can still extrapolate the info with a single query.

 

I stated to only pull the 'username' field because of efficiency. There is no need to pull the content when you are only interested in the count.

 

I'm not.  Do you not understand the code I provided?  You're the one pulling extra information out when you only need MySQL to select 1 username.  Not only that you're putting all of them in an array and performing multiple methods on it.  Very inefficient... 

 

This is a PHP problem, not a MySQL problem.

 

Wrong.

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/162419-find-biggest-poster/#findComment-857495
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.