查询时间戳间隔时出现mysql错误

时间:2012-10-13 15:29:23

标签: php mysql

我有投票_IP表如下:

+-----------+-------------+------+-----+---------+----------------+
| Field     | Type        | Null | Key | Default | Extra          |
+-----------+-------------+------+-----+---------+----------------+
| ip_id     | int(11)     | NO   | PRI | NULL    | auto_increment |
| mes_id_fk | int(11)     | YES  | MUL | NULL    |                |
| ip_add    | varchar(40) | YES  |     | NULL    |                |
| timestamp | datetime    | YES  |     | NULL    |                |
+-----------+-------------+------+-----+---------+----------------+

我想运行这个有错误的查询,我不知道如何纠正它?

$ip_sql=mysql_query("select ip_add from Voting_IP where mes_id_fk='$id' and ip_add='$ip' and timestamp > (DATE_ADD(now(), INTERVAL -1 HOUR);)");

我也试过这个:

$ip_sql=mysql_query("select ip_add from Voting_IP where (mes_id_fk='$id' and ip_add='$ip' and timestamp > (DATE_ADD(now(), INTERVAL -1 HOUR);))");

1 个答案:

答案 0 :(得分:2)

INTERVAL -1 HOUR);))");
                 ^-----here is the error extra semicolon 

您可以通过mysql_query("your query ") or die(mysql_error())

查看错误

替换为:

INTERVAL -1 HOUR))");