Jump to content
  • Advertisement
Sign in to follow this  
Zyklon

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

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!