I'm sending the variable "lasttime" via POST to my PHP script. This variable contains a timestamp as a string. In my MySQL database I have a column 'time'. This column has the type 'TIMESTAMP' and by updating the current timestamp is entered.

I want to select all rows from the database which have a timestamp after the timestamp in the variable $lasttime.

My query:

SELECT * FROM mytable WHERE UNIX_TIMESTAMP(time) > '$lasttime'

The problem is, that all rows are returned. How can I fix that?

有帮助吗?

解决方案 3

I have changed it now to

$time = date("Y-m-d H:i:s", $lasttime); SELECT * FROM mytable WHERE timediff('$time',time) < 0

and it works fine...

其他提示

If you are passing in $lasttime a string formatted datetime (e.g. 2014-04-19 03:04:05), you have first to normalized it to unixtime: $unixtime = strtotime($lasttime) Then the sql query will look like SELECT * FROM mytable WHERE UNIX_TIMESTAMP(time) > $unixtime

Is it possible to do it this way?
$time = date("Y-m-d H:i:s", $lasttime); SELECT * FROM mytable WHERE timediff('$time',time) > 0

time is the column in the database.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top