Gary
Gary

Reputation: 1011

mysql query with lots of conditions

I realise this is probably an absolutely horrible way to do a query, and of course its not working. The point of it is to select users based on a date range and a keyword.

$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");

Upvotes: 0

Views: 146

Answers (2)

mustafa
mustafa

Reputation: 745

Use mysql_error() to print the 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());

Upvotes: 0

Maxim Krizhanovsky
Maxim Krizhanovsky

Reputation: 26749

You are missing the brackets in the query

$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");

Upvotes: 1

Related Questions