BETWEEN query not working

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Wardy7
Forum Commoner
Posts: 38
Joined: Wed Aug 24, 2005 4:45 am
Location: UK

BETWEEN query not working

Post by Wardy7 »

Having problems getting one part of a query working on a site. It's just the last part of the query where I am searching for records that are set between a certain year.

Code: Select all

$query  = "SELECT * FROM *MYTABLE* WHERE make='$make' AND model LIKE '%$model%' AND WHERE $year between madefrom AND madeto LIMIT $limitvalue, $limit";
So the above searches that the year that was selected is between the "madefrom" year and the "madeto" year (well it should but it isn't working, can anyone help please?! :)

I have also tried changing the last bit to this but still had no luck gettign it to work

Code: Select all

WHERE $year between datepart(yy,madefrom) AND datepart(yy,madeto)
Cheers
Wardy
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

You have double "WHERE" in you query - remove the second one.
There are 10 types of people in this world, those who understand binary and those who don't
Wardy7
Forum Commoner
Posts: 38
Joined: Wed Aug 24, 2005 4:45 am
Location: UK

Post by Wardy7 »

Soooo simple. Nice one mate :)

Cheers
Wardy
Post Reply