i have a simple question, that just needs verification, it’s about how time is stored in mysql, here is how i store it:
if(isset($_SESSION['user']))
{
$u_id=$_SESSION['user'];
//insert current time to db, i set the type of time to TIME
$query="INSERT INTO time(id,u_id,time) VALUES('NULL','".$u_id."',CURTIME())";
mysql_query($query);
}
that is how i store it, now i would also need to compare it to a value, later on:
//set current time
$curr_time=time();
//set maximum time to 5min
$max=300;
//get previous time from db
$query="SELECT * FROM time";
$result=mysql_query($query);
$row=mysql_fetch_array($result);
$prev_time=$row['time'];
//get difference in time
$diff=$curr_time-$prev_time;
//if max time is surpassed
if($diff>$max)
{
echo "maximum time surpassed!";
}
that’s the simple code, first of all, is the syntax for inserting the time to the table okay(the CURTIME() thing), also is the comparison fine, will the result stored in $diff yield seconds?thank you, and sorry if you think this question is a waste of time.
CURTIME()will only give you the time, you likely wantNOW()which is the date and time. Then you will need to usestrtotimeto convert the saved value from the database to seconds since epoch.