有很多条件的mysql查询

时间:2012-01-14 16:47:37

标签: php mysql

我意识到这可能是一种绝对可怕的查询方式,当然它不起作用。重点是根据日期范围和关键字选择用户。

$query = mysql_query("SELECT * FROM my_users WHERE my_regdate BETWEEN '$ftimestamp' AND '$ttimestamp' AND my_username LIKE '%$trimmed%' OR my_realname LIKE '%$trimmed%' OR my_email LIKE '%$trimmed%' ORDER BY my_id");

2 个答案:

答案 0 :(得分:1)

您缺少查询中的括号

$query = mysql_query("SELECT * FROM my_users WHERE my_regdate BETWEEN '$ftimestamp' AND '$ttimestamp' AND (my_username LIKE '%$trimmed%' OR my_realname LIKE '%$trimmed%' OR my_email LIKE '%$trimmed%') ORDER BY my_id");

答案 1 :(得分:0)

使用mysql_error()打印错误。

$query ="SELECT * FROM my_users WHERE my_regdate BETWEEN '$ftimestamp' AND '$ttimestamp' AND my_username LIKE '%$trimmed%' OR my_realname LIKE '%$trimmed%' OR my_email LIKE '%$trimmed%' ORDER BY my_id";
$res= mysql_query($query) or die(mysql_error());