changing timestamp in mysql with php

I am creating a racing game and hit a snag. Been working on this all day (and most of the night)

I need to set up the races so that players can enter them and race, then when the races is over it resets it with a random 10 to 30 minutes til the next race

I have tried all sorts of things to get this to work. I have gotten closer and closer but here is where I stand now.

lets say a race just ended, instead of resetting the time and adding 10 to 30 minutes, it sets everything to 0, it makes me think the variable is not valid and it tries to enter. this is what I’ve come up with after trying it at least 50 different ways (the error is in the IF statement)

[php]

Car Entered <?php $user="****"; $password="****"; $database="****"; mysql_connect("localhost",$user,$password); @mysql_select_db($database) or die( "Unable to select database");
	$query="SELECT * FROM races";
	$result=mysql_query($query);
	$num=mysql_num_rows($result);
	
	$query2="SELECT * FROM account";
	$result2=mysql_query($query2);
	$num2=mysql_num_rows($result2);

	$query3="SELECT * FROM tracks";
	$result3=mysql_query($query3);
	$num3=mysql_num_rows($result3);	

	$i=0;
	$datetimeNOW = date("Y-m-d H:i:s ");

?>
Current date/Time: <? echo $datetimeNOW; ?>

<? while ($i < $num) { $RaceStart = mysql_result($result,$i,"start"); $Track = mysql_result($result,$i,"track"); $i++; if ($RaceStart > $datetimeNOW) { ?>

<? } else { ?> <? if ($Track == "Monthly Test" ) { // 1 exact month = 43830 $addrandminutes = rand(43200, 46080); // 30 to 32 days $newdate = strtotime('$datetimeNOW + $addrandminutes minutes'); $queryreset = "UPDATE races SET start = '$newdate' WHERE track = '$Track'"; mysql_query($queryreset); } else if ($Track == "Weekly test" ) { // 1 week = 10080 $addrandminutes = rand(9360, 10800); // 6.5 to 7.5 days $newdate = strtotime('$datetimeNOW + $addrandminutes minutes'); $queryreset = "UPDATE races SET start = '$newdate' WHERE track = '$Track'"; mysql_query($queryreset); } else { $addrandminutes = rand(10, 30); $newdate = strtotime('$datetimeNOW + $addrandminutes minutes'); // 10 to 20 minutes $queryreset = "UPDATE races SET start = '$newdate' WHERE track = '$Track'"; mysql_query($queryreset); } } } mysql_close(); ?>
Track Race Started? Race Start Time
<? echo $Track; ?> <? echo "not started yet"; ?> <? echo $RaceStart; ?>
<? echo $Track; ?> <? echo "Race Started"; ?> <? echo $RaceStart; ?>
[/php]

Let me know what else I need to post, and thank you very much in advance for any help you can give me, both to fix this problem, and in helping me understand it

I realize I forgot to edit out my db password, since I couldn’t find any modify or edit post links/buttons I had to go and chance the password… so don’t get any ideas :stuck_out_tongue:

change*

arg y’all really need to allow editing of posts

try this:

$addtime = ("+" . rand(10, 30) . " minutes");
$newtime = new DateTime();
$newtime->modify($atime);

where is $atime defined?

Sponsor our Newsletter | Privacy Policy | Terms of Service