PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have been programming a tick/turn-based mmorpg which is almost ready to enter alpha-testing! Though i have run into one little bit of trouble, the cron script that i will run, wont rank, this only relates to two line of the whole code. I will indent the part of the code that isnt working, can someone help me figure this out. The ranking code takes the players power and sorts the players by their power and ranks them 1st, 2nd, etc. Except it is just giving the players they're ranks as of when they joined, even when they are all reset to 0! Anyways, heres the code:
<?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");
}
?>
<?php
include 'config.php';
function db_query($query) {
$result = mysql_query($query) or die(mysql_error().': '.$query);
return $result;
}
$minutes = mysql_result(db_query("SELECT * FROM `cron` WHERE id = '1'"),0,"minutes");
if($minutes)
{
$minutes--;
db_query("UPDATE `cron` SET `minutes`='$minutes' WHERE id = '1'");
}
else
{
db_query("UPDATE `cron` SET `minutes`='4' WHERE `id` = '1'");
db_query("UPDATE `user` SET `gold`=`gold`+ROUND(`land`/2),`turns`=`turns`+1, `power`=ROUND(`gold`/1000 + `troops`*100 + `land` + `generals`*20)");
db_query("set @i=0");
db_query("UPDATE `user` SET `rank`=(@i:=@i+1) ORDER BY `power` DESC");
}
?>
I tested the edited code you gave me there was no reply and no error said it just left the blank page, and did what it had been doing in previous attempts.
Within that same script you say is having problems, try echo'ing out anything. If that echo shows up, then there is no return values coming from the rest of your script. If the page is still totally black, then there is still a syntax error of some sort. You may also want to change error reporting to E_ALL. That will show more error details than what you have currently.
i ran the script with echoing that volka posted and got junk, his script doesnt work at all gives crap output... any ideas why this is happening? it all works though up until one part of my script.
Hey, just another note on this, i had someone help me with it and am not to experienced as i look i had no idea how to do loops and order within mysql.(sorry for dp)