SpyGuy007:
The user's points are stored in a field that is VARCHAR. String sorting is different from numeric sorting, so you can't query the database in the numeric sense. If you have phpmyadmin, you can verify this by going to the userfield table, clicking on browse, then clicking the field5 column. Note how the values appear to be out of place based onwhat you would expect. There might be another way to do it, however.
EDIT: After a little research, I think this will work:
PHP Code:
$mostpoints = $DB_site->query_first("SELECT round(userfield.field5) as field5,userfield.userid,user.username FROM userfield LEFT JOIN user ON user.userid=userfield.userid ORDER BY field5 DESC");
In the forumhome template, you can now try using the following variables:
$mostpoints[userid] - User ID of the person with the most points
$mostpoints[username] - Username of the person with the most points
$mostpoints[field5] - Amount of points the person with the most points has.
EDIT2:
I just did a little more experimentation. I realized that since there are two separate places where you store the amount of money the user has, then you may want to show the person who has the most overall money. The person with the most overall money is the person that has the most money in their pocket (most points) AND the most money in the bank. To do all of this in one query, you can do the following:
PHP Code:
$mostpoints = $DB_site->query_first("SELECT round(userfield.field5) as field5,items_user.bankval,round(userfield.field5+items_user.bankval) AS total,userfield.userid,user.username
FROM userfield
LEFT JOIN user ON user.userid=userfield.userid
LEFT JOIN items_user ON items_user.userid=userfield.userid
ORDER BY total DESC");
In the forumhome template, you can now try using the following variables:
$mostpoints[userid] - User ID of the person with the most overall money
$mostpoints[username] - Username of the person with the most overall money
$mostpoints[field5] - Amount of points the person with the most overall money has
$mostpoints[bankval] - Amount of money the person with the most overall money has in the bank
$mostpoints[total] - Amount of money the person with the most overall money has total (points + bank)
On my test forums, this was a rather fast query:
Code:
Time before: 0.0881650447845
Time after: 0.0895960330963