FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Richest User





DanielXP
I have a user system and points for each user and i want to make a script that gets the top 10 richest people from the database.

Could any one help me?
hexkid
DanielXP wrote:
I have a user system and points for each user and i want to make a script that gets the top 10 richest people from the database.

Could any one help me?


Replace what I put between angle brackets with the appropriate thing for your database
Code:
<?php
$con = mysql_connect(<DBHOST>, <DBUSER>, <DBPASS>);
if (!mysql_select_db(<DBNAME>)) {
  exit('Database unavailable: ' . mysql_error());
}
$sql = "SELECT <name> FROM <table> ORDER BY <wealth> DESC LIMIT 10";
$res = mysql_query($sql) or die('Error in query: ' . mysql_error());
while ($row = mysql_fetch_row($res)) {
  echo $row[0], "<br>\n";
}
mysql_free_result($res);
mysql_close($con);
// ...
DanielXP
Where will that find out who has the biggest number?


in users where the username and points is the db info
hexkid
DanielXP wrote:
Where will that find out who has the biggest number?

The SQL command will do that.
It will return 10 (LIMIT 10) names ordered by wealth (ORDER BY <wealth>) in a decreasing order (DESC), so the first result returned is the richest name in the database.

DanielXP wrote:
in users where the username and points is the db info
???????????
vignesh_natraj
jus get that variable and compare the values using arrays and then sort accordingly it is usually done that way
DSitC
vignesh_natraj wrote:
jus get that variable and compare the values using arrays and then sort accordingly it is usually done that way

Wrong. If you have a database, use the internal sorting. It's faster by a wide margin. In most cases. Wink
Related topics
Spying on the spyware makers
Point to the user online
350 x 20 User Bar + Tutorial
Dynamic User Customizable Sites. CSS + PHP = Awesome!
User Membership Script Needed....In Trouble really need 1 !
Javascript to create non-Sidebar bookmark in Firefox?
Aha! Now I know why Bondings hates...
Bill Gates $$
Give each user a sub directory?
A user/profile management system
Follow the user
How hard is it to make a user database.
How to Block shared network drive accesss for Limited User??
User Authentication
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.