FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a 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
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

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