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