Reputation: 4163
This is the code I have:
$qry = "SELECT *
FROM parties
WHERE schoolid = $schoolid AND
WHERE timestart BETWEEN '$dateStart 00:00:00' AND '$dateEnd 23:59:59'
ORDER BY timestart, attending";
This is what I get when I echo the query:
SELECT *
FROM parties
WHERE schoolid = 100 AND
WHERE timestart BETWEEN '2013-08-13 00:00:00' AND '2013-09-12 23:59:59'
ORDER BY timestart, attending
It doesn't work. And when I manually run the code in PHPMyAdmin it just tells me I have an error in my syntax. What is wrong?
Upvotes: 0
Views: 48
Reputation: 665
There should be only one WHERE in query unless subquery is used.
Upvotes: 0
Reputation: 3297
SELECT *
FROM parties
WHERE schoolid = 100 AND
timestart BETWEEN '2013-08-13 00:00:00' AND '2013-09-12 23:59:59'
ORDER BY timestart, attending
Remove the AND WHERE
, it's syntactically incorrect - the correct one is a lonely AND
on that spot.
Upvotes: 1
Reputation: 622
you are typing WHERE
twice and it has to be only once.
should be like this:
SELECT *
FROM parties
WHERE schoolid = 100 AND
timestart BETWEEN '2013-08-13 00:00:00' AND '2013-09-12 23:59:59'
ORDER BY timestart,attending
Upvotes: 1