Forum Moderators: coopster
Thank you
Dylan
On the other hand if you are looking to have a sungle rank assigned to every player to display it individually within their account then you will still need the cron.
The cron would be fairly intense really.
to get the users in order:
select username from usertable order by rank asc
load all users into an array in order, you could slap the rank right in there if you wanted as well
then run an update for each one in a loop:
update usertable set rank=x where username='someusername'
should pretty much do it
Suggestions for alterations are as always requested.
$result = mysql_query("SELECT * FROM user_char order by points * 1 desc", $link) or die ("query 1: " . mysql_error());
$i = 0;
while ($row = mysql_fetch_array($result))
{
$i = ++$i;
echo $i.''.$row[name].'<br>';
$rankupdate = mysql_query("UPDATE user_char SET rank = '$i' WHERE username ='$row[username]'", $link);
if ($rankupdate == TRUE)
{
echo 'updated';
}
}
$result = mysql_query("SELECT * FROM user_char order by points * 1 desc", $link) or die ("query 1: " . mysql_error());
$i = 1;
while ($row = mysql_fetch_array($result)) {
$rankquery = "UPDATE user_char SET rank = '$i' WHERE username ='" . $row[username] . "'";
$rankupdate = mysql_query($rankquery);
echo $i.''.$row['name'].'<br>';
if ($rankupdate == TRUE) echo 'updated';
$i++;
}
all I really did was construct the update query in a var and pass the var to the mysql_query function. I also maoved a couple lines and initialized the counter to 1 instead of 0
when someone casts a vote on anything they are allowed to vote on, I first check a separate table if they already have voted for the concerning item, if not, I get the current overall points, add the user's rating to it and divide this by (current number of votes +1). but maybe I am getting the wrong idea here of what you are trying to do
This is the script.
$result = mysql_query("SELECT * FROM user_char order by points * 1 desc", $link) or die ("query 1: " . mysql_error());
$i = 1;
while ($row = mysql_fetch_array($result)) {
$rankquery = "UPDATE user_char SET rank = '$i' WHERE username ='" . $row[username] . "'";
$rankupdate = mysql_query($rankquery);
echo $i.''.$row['name'].'<br>';
if ($rankupdate == TRUE) echo 'updated';
$i++;
}
This was the output
1dkin69
updated2JIMBOB
3winky
4Mr. Peanut
updated5KILLER
updated6hjkjhk
updated7Makaveli
updated
I am not good with scripts like this, it has been baffling me for days. please help :D. Thank you.