# Need a little help with my cron script...(in php)

This topic is 4316 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Ok, i had thought it had been working, and i know this will sound a little noobish, bu i've almost finished programming (version 1) my php turn/tick based game, only to find out that the ranking part of my cron script isn't ranking but actually just putting them in order by the time they joined, or id number which increases by one every time per new person. Anyways heres the code and i'll indent the lines in which the trouble is appearing!
<?php
include'config.php';
$minutes = mysql_result(mysql_query("SELECT * FROM cron WHERE id = '1'"),0,"minutes"); if($minutes)
{
$minutes--; mysql_query("UPDATE cron SET minutes='$minutes' WHERE id = '1'");
}
else
{
mysql_query("UPDATE cron SET minutes='4' WHERE id = '1'");
mysql_query("UPDATE user SET gold=gold+ROUND(land/2),turns=turns+1, power=ROUND(gold/1000 + troops*100 + land + generals*20)");
mysql_query("set @i=0");
mysql_query("UPDATE user SET rank=(@i:=@i+1) ORDER BY power DESC");
}
?>


[Edited by - Zyklon on July 27, 2006 9:07:29 PM]

##### Share on other sites
I don't think the "ORDER BY" on the "UPDATE" works the way you want it to.

Easiest is to just sort/rank the users when you display the ranking; sorting even 100 users isn't going to take any appreciable time.

If you, for some reason, need to have the table in order (or have the rank in the table), you can accomplish this with temp tables that you then use to replace the contents in your 'user' table with, or just update the user table from.

• 15
• 9
• 13
• 41
• 15