Jump to content

PHP Top 100 Posters?


MrLols

Recommended Posts

For a forum I have, I was wondering how to get the top 100 Posters :P I tried but kept getting errors & stuff so I decided to start fresh ;)

 

This is my counter of posts and topics :

 

<?php
    $select = mysql_query("SELECT * FROM `posts` WHERE `post_by`='" . $pid . "' AND `post_first`='no';");
    $posts = 0;
    while ($row = mysql_fetch_array($select))
    {
        $posts += 1;
    }
    echo "Posts: " . $posts . PHP_EOL . nl2br(PHP_EOL) . PHP_EOL;
    $selectx = mysql_query("SELECT * FROM `topics` WHERE `topic_by`='" . $pid . "';");
    $topics = 0;
    while ($trow = mysql_fetch_array($selectx))
    {
        $topics += 1;
    }
    echo "Topics: " . $topics. PHP_EOL . nl2br(PHP_EOL) . PHP_EOL;
}

 

How would I make it count user_id's from the database , and make it list the top 100 with the most posts? My table for users is :

 

user_id ; the ID of the user

 

user_name ; name

 

etc.

 

MOD EDIT: code tags added.

Link to comment
https://forums.phpfreaks.com/topic/244237-php-top-100-posters/
Share on other sites

you are reading the entire table just to get a count...

 

you don't need select * for that, you also don't need to loop through the results, you can just use mysql_num_rows or just count().

 

also,

 

$select = mysql_query("SELECT * FROM `posts` WHERE `post_by`='" . $pid . "' AND `post_first`='no';");

 

does not require a semicolon in the statement (after `fist_post`='no')

Link to comment
https://forums.phpfreaks.com/topic/244237-php-top-100-posters/#findComment-1254445
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.