• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

a little php help...

kjavia795

New Member
ok im trying to list the top 10 richest users on my website. I wanted it to be listed like:

USER1
USER2
USER3
and so on


the users are in the database easymazu_easy and the table is called mybb_users and the row that has all of the total amounts of moeny earned is called totalearnings

can somebody plz make me a small code that will order the top 10 users from greatest to least in a list like above? thx a lot.
 
PHP:
<?php
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("easymazu_easy") or die(mysql_error());
$query = "SELECT * FROM mybb_users ORDER BY totalearnings DESC LIMIT 10"; 	 
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
	echo $row['user']. " - ". $row['totalearnings'];
	echo "<br />";
}
?>

Change username to your mysql username, password to your mysql password and ''user' to the name of the column that contains the username of your users.

It'll display like this:

User1 - $10,000
User2 - $5,000
User 3 - $3,000

You can play around with it. It should work.
 
Last edited:
ok i got an error on this line:

$query = "SELECT * FROM mybb_users ORDER BY totalearnings DESC LIMIT 10";

t variable or something
 
Parse error: syntax error, unexpected T_VARIABLE in /home/easymazu/public_html/index.php on line 227

i cant leave it on a page, i have too many members to leave it up
 
Post the code I gave you back here. Because I just took my code and tried it on another side and it works as coded.
 
<?php
mysql_connect("localhost", "easymazu_kjavia7", "********") or die(mysql_error());
mysql_select_db("easymazu_easy") or die(mysql_error())
$query = "SELECT * FROM mybb_users ORDER BY totalearnings DESC LIMIT 10";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo $row['user']. " - ". $row['totalearnings'];
echo "<br />";
}
?>
 
Is that the code you're using? Is 'user' is the name of the column in your MySQL Db that contains the user's username?
 
i fixed it to username, but its still showing an error on the 4th line... this line:

$query = "SELECT * FROM mybb_users ORDER BY totalearnings DESC LIMIT 10";

and everything on that seems to be correct
 
If that doesn't work, the only thing I can suggest is you posting the entire page's source that you are using that code in to see if there is something interfering with it -- as the code by itself works.

Or create a new php file and include JUST the code I gave you and see if you get the error (and if you do, you can link me to that individual page as nobody will see it)
 
I want to see the source code for test.php. I've combed the code and you shouldn't be receiving the error. if you're using php5, maybe that's why, but I don't know why.
 
<?php
mysql_connect("localhost", "easymazu_kjavia7", "*****") or die(mysql_error());
mysql_select_db("easymazu_easy") or die(mysql_error())
$query = "SELECT * FROM 'mybb_users' ORDER BY 'totalearnings' DESC LIMIT 10";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo $row['username']. " - ". $row['totalearnings'];
echo "<br />";
}
?>

thats the code.... can anybody else help me?
 
ok same error

<?php
mysql_connect("localhost", "easymazu_kjavia7", "********") or die(mysql_error());
mysql_select_db("easymazu_easy") or die(mysql_error())
$query = "SELECT * FROM mybb_users ORDER BY totalearnings DESC LIMIT 10";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo $row['username']. " - ". $row['totalearnings'];
echo "<br />";
}
?>
 
Last edited:
Back
Top