PDA

View Full Version : game reset



Demonicman
10-05-2007, 10:12 PM
i am trying to make the game reset, i attempted but i KNOW its not right coding

can you help me change it so that it does what i want it to do?


<?php
include('connect.php');
$now = time ($a, $b, $c, $d, $e, $f) ;


$thetime = mysql_fetch_array(mysql_query("select * from time"));

mysql_query("update time set minute=$b, second=$c, day=$d, month=$e, year=$f");

if (a$ > $thetime[hour] ) {

mysql_query("update time set hour=$a");

mysql_query("update km_users set pj=maxpj");
mysql_query("update km_users set hp=maxhp where hp<maxhp");
mysql_query("update km_users set battles=0");
}

?>

djr33
10-05-2007, 10:27 PM
As in the other thread, you should consult a PHP tutorial. There are a lot of things just wrong with the script that you can learn.
http://php-mysql-tutorial would apply here as well.

1. It's generally function(...), not function (...). Not a big issue, but odd and less readable.
2. time() has no arguments. It returns the number of seconds since 1970, which can be used to create a readable date with date(), etc. It's something like 110000000 right now.
3. $thetime will not do anything... I'm not sure what you want with it.
Using mysql_query with SELECT will return a SET of results. See the tutorial above for how to deal with this. mysql_fetch_array will return only the first of the returned rows (and there are almost certainly many rows as there is no limit or where requirement, etc.). Using it as is will just get the first one.
4. Your update query that is wrong, as those variables aren't defined. And the entire query is just the wrong syntax, and there is no where requirement, so it would pick one at random, I guess. Look that up.
5. Why are the last few lines indented and the one above not? You should be consistent so it's easy to read.
6. the last queries seem fairly reasonble, but still not very controlled.

Demonicman
10-05-2007, 10:39 PM
so could i set each number in the time function as a variable?

djr33
10-05-2007, 10:44 PM
I dunno what you're trying to do.
date() will give you a usable representation of time().
http://www.php.net/manual/en/function.date.php

Demonicman
10-05-2007, 11:02 PM
<?php
include('connect.php');

$now = date(H);

$thetime = mysql_fetch_array(mysql_query("select * from time"));

if ($now > $thetime[hour] ) {

mysql_query("update time set hour=$now");
mysql_query("update km_users set pj=maxpj");
mysql_query("update km_users set hp=maxhp where hp<maxhp");
mysql_query("update km_users set battles=0");
}

?>


could that work?

djr33
10-05-2007, 11:11 PM
1. You are still not uses quotes for the keys to arrays.
['hour'], not [hour].
2. date(H) will give an error. Quotes. date('H').
3. Tabs are still a bit weird.
4. You aren't limiting those updates. Are you sure you want to do that? Just change all records? (except the third.)

Demonicman
10-05-2007, 11:13 PM
lol for number 4 the answer is yes :)