Josh Boothe
Josh Boothe

Reputation: 1423

Using many ands in SQL

I am having problems using many and statements in the WHERE statement.

When I have this line of PHP:

$where .= " AND post_date >= '$app_time'";

It works just fine, however when introducing this:

$where .= " AND post_date >= '$app_time' AND post_date <= '$app_timeTwo'";

It causes it to display results which do NOT fit in between 2 times. $app_time and $app_timeTwo are a _$GET['']; parameter, sent from a URL from an iPhone app. They are the correct format.

Any reason why using two ands breaks it? Thanks.

Upvotes: 1

Views: 177

Answers (2)

Code Lღver
Code Lღver

Reputation: 15603

Use the below code:

$where .= " AND post_date BETWEEN '$app_time' AND '$app_timeTwo'";

Upvotes: 0

Vipul
Vipul

Reputation: 325

Use "between" clause instead of using multiple "and" in second query and make sure that datatype of "post_date" is datetime ..

Upvotes: 1

Related Questions