TEENFRONT Posted May 23, 2007 Share Posted May 23, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/52727-figure-out-the-users-rank/ Share on other sites More sharing options...
pocobueno1388 Posted May 23, 2007 Share Posted May 23, 2007 First of all, why do you have all your users separated into 5 separate tables? Quote Link to comment https://forums.phpfreaks.com/topic/52727-figure-out-the-users-rank/#findComment-260320 Share on other sites More sharing options...
TEENFRONT Posted May 23, 2007 Author Share Posted May 23, 2007 for speed.. i have 147,000 users and all 5 of the tables have a 30,000 record limit, then it automatically creates a 6th tables and starts to populat that. Quote Link to comment https://forums.phpfreaks.com/topic/52727-figure-out-the-users-rank/#findComment-260325 Share on other sites More sharing options...
TEENFRONT Posted May 23, 2007 Author Share Posted May 23, 2007 i have no problem ordering the 5 tables by games_won .... thats a simple order by command, but i need to know how to keep that whole order and display the rank for $username only. Quote Link to comment https://forums.phpfreaks.com/topic/52727-figure-out-the-users-rank/#findComment-260339 Share on other sites More sharing options...
TEENFRONT Posted May 24, 2007 Author Share Posted May 24, 2007 been reserching and im really stuck on this, any help? cheers Quote Link to comment https://forums.phpfreaks.com/topic/52727-figure-out-the-users-rank/#findComment-260397 Share on other sites More sharing options...
TEENFRONT Posted May 24, 2007 Author Share Posted May 24, 2007 still having difficulty with this, does anyone know how to order the results of 5 tables, keep that order and display "$username is $rank of $totalusers", this would show "Adam is 5th of 200" Quote Link to comment https://forums.phpfreaks.com/topic/52727-figure-out-the-users-rank/#findComment-261056 Share on other sites More sharing options...
fou2enve Posted May 24, 2007 Share Posted May 24, 2007 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/')); ?> Quote Link to comment https://forums.phpfreaks.com/topic/52727-figure-out-the-users-rank/#findComment-261093 Share on other sites More sharing options...
TEENFRONT Posted May 25, 2007 Author Share Posted May 25, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/52727-figure-out-the-users-rank/#findComment-261278 Share on other sites More sharing options...
fou2enve Posted May 25, 2007 Share Posted May 25, 2007 awesome. glad you figured it out. Quote Link to comment https://forums.phpfreaks.com/topic/52727-figure-out-the-users-rank/#findComment-261476 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.