Jump to content

figure out the users rank..


TEENFRONT

Recommended Posts

Hey

 

I have a sql query..

 

$result = mysql_query("(select * from gamezer_users_1) UNION  (select * from gamezer_users_2) UNION  (select * from gamezer_users_3) UNION (select * from gamezer_users_4) order by games_won  desc limit 15");

 

Thats grabs all the data from all 5 of the user tables.

 

I need to be able to pass $username to the query and show "you are rank $rank ( EG 1) of $totalusers (EG 140,000)"

 

i dont know how to figure out and order all 5 tables by games won then give a rank for $username of of all the users..

 

any help?

Link to comment
Share on other sites

are you looking for an instantaneous search? or like something at X interval? because what you may be able to do, is set up a cron job and have it run the query and output to a text file. Then have php find the username and based on what line number in the text file the username appears that would be their rank. I'm not sure how exactly to do this but in theory it sounds like it could work, the only thing would be figguring out what line number your on, the rest i know is possible.

 

you might even be able to just have php count it, if its not something that fopen supports, or their may be some wrappers that may support that.

 

from php.net/file

 

<?php
// Get a file into an array.  In this example we'll go through HTTP to get
// the HTML source of a URL.
$lines = file('http://www.example.com/');

// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
    echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
}

// Another example, let's get a web page into a string.  See also file_get_contents().
$html = implode('', file('http://www.example.com/'));
?> 

Link to comment
Share on other sites

Hey

 

Sorted this now.. just to let you know this is what iv done..if it helps anyone in the future. Long way round but it turned out pretty good for speed and server performance due to the cron.

 

rank-cron.php

Runs every 15mins

Orders all user tables by games won, therefore giving them a rank.

Writes top 1000 players by rank to a .txt file like this "$rank:$username\n"

 

user-rank.php?username=timmy!

Searches txt file for $username if found it split the line into $rank and $username using explode ( splitting the : sign )  I then show the rank to the user...woo lol.

 

 

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.