Page 1 of 1
mysql_queries arnt working in my script! plz HELP!
Posted: Mon Jul 31, 2006 7:21 pm
by zyklon
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:
Code: Select all
<?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");
}
?>
Posted: Tue Aug 01, 2006 5:30 am
by volka
no error handling at all? no wonder you can't find the error.
Try
Code: Select all
<?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");
}
?>
Posted: Tue Aug 01, 2006 9:21 am
by zyklon
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.
Posted: Tue Aug 01, 2006 9:26 am
by RobertGonzalez
A blank page is probably going to be a syntax error. Check your code for unmatched brackets and missing semicolons. Or turn display_errors to On.
Posted: Tue Aug 01, 2006 9:26 am
by volka
no output at all is seldom usefull.
So let's add some unconditional echos
Code: Select all
<?php
ini_set('display_errors', true); error_reporting(E_ALL);
include 'config.php';
function db_query($query) {
echo $query, ' - ';
$result = mysql_query($query) or die(mysql_error().': '.$query);
echo 'affected rows: ', mysql_affected_rows(), "\n";
return $result;
}
echo 'start: ', date('H:i:s d.m.Y'), "\n";
$minutes = mysql_result(db_query("SELECT * FROM `cron` WHERE id = '1'"),0,"minutes");
echo 'minutes: ', $minutes, "\n";
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");
}
echo 'end: ', date('H:i:s d.m.Y'), "\n";
?>
Posted: Tue Aug 01, 2006 9:28 am
by feyd
To get a baseline of your settings run the following in a new file and tell us the results please.
Code: Select all
<?php
$neg = array(0, false, '', null, 'off');
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
$rg = (in_array(strtolower(ini_get('register_globals')), $neg) ? 'Off' : 'On');
$de = (in_array(strtolower(ini_get('display_errors')), $neg) ? 'Off' : 'On');
$so = (in_array(strtolower(ini_get('short_open_tag')), $neg) ? 'Off' : 'On');
$le = '';
$cli = (php_sapi_name() == 'cli');
$eol = ($cli ? "\n" : "<br />\n");
$gle = get_loaded_extensions();
$rows = array();
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
$le .= ' ' . implode(' ', array_slice($gle, $i, $wide)) . "\n";
}
if ($cli)
{
$le = $eol . $le;
}
else
{
$le = '<pre>' . $le . '</pre>';
}
$ec = array(
'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);
$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
if (($t & $v) == $v)
{
$e[] = $n;
$t ^= $v;
}
}
$er = $er . ' (' . implode(' | ', $e) . ')';
if (!$cli)
{
echo '<html><head><title>quick info</title></head><body>' . "\n";
}
echo 'PHP Version: ' . $ve . $eol;
echo 'PHP OS: ' . $os . $eol;
echo 'Error Reporting: ' . $er . $eol;
echo 'Register Globals: ' . $rg . $eol;
echo 'Short Tags: ' . $so . $eol;
echo 'Display Errors: ' . $de . $eol;
echo 'Loaded Extensions:' . $le . $eol;
if (!$cli)
{
echo '</body></html>' . "\n";
}
?>
Posted: Tue Aug 01, 2006 9:53 am
by zyklon
feyd,
Code: Select all
PHP Version: 4.2.3
PHP OS: WINNT
Error Reporting: 2039 (E_USER_NOTICE | E_USER_WARNING | E_USER_ERROR | E_COMPILE_WARNING | E_COMPILE_ERROR | E_CORE_WARNING | E_CORE_ERROR | E_PARSE | E_WARNING | E_ERROR)
Register Globals: Off
Short Tags: On
Display Errors: On
Loaded Extensions:
standard bcmath calendar com
ftp mysql odbc pcre
session xml wddx dbase
gd sockets zlib Zend Optimizer
apache
I mean for there to be no output on the page, its my cron script, and i m using phpdev423 to develop it.
Posted: Tue Aug 01, 2006 10:14 am
by RobertGonzalez
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.
Posted: Thu Aug 10, 2006 12:41 pm
by zyklon
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.
(I was away for a week)
Posted: Thu Aug 10, 2006 1:05 pm
by volka
do you mind letting us in on the crappy output?
Posted: Thu Aug 10, 2006 6:30 pm
by zyklon
Volka,
On the ones when minutes are not equal to 0 this is what it outputs:
Code: Select all
start: 19:31:39 10.08.2006 SELECT * FROM `cron` WHERE id = '1' - affected rows: 1 minutes: 4 UPDATE `cron` SET `minutes`='3' WHERE id = '1' - affected rows: 1 end: 19:31:39 10.08.2006
otherwise it outputs:
Code: Select all
start: 19:30:00 10.08.2006 SELECT * FROM `cron` WHERE id = '1' - affected rows: 1 minutes: 0 UPDATE `cron` SET `minutes`='4' WHERE `id` = '1' - affected rows: 1 UPDATE `user` SET `gold`=`gold`+ROUND(`land`/2),`turns`=`turns`+1, `power`=ROUND(`gold`/1000 + `troops`*100 + `land` + `generals`*20) - affected rows: 3 set @i=0 - affected rows: 0 UPDATE `user` SET `rank`=(@i:=@i+1) ORDER BY `power` DESC - affected rows: 0 end: 19:30:00 10.08.2006
Posted: Sat Aug 12, 2006 10:28 am
by zyklon
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)