Click to See Complete Forum and Search --> : mysql_query
CreativeForce
02-23-2009, 02:10 PM
i have a simple form with input fields, one for title $_GET['title']=$title, year $_GET['year']=$year, from_year $_GET['from_year']=$from_year, to_year $_GET['to_year']=$to_year.
i then wish to make a search.
$query="SELECT * FROM mydb WHERE title LIKE '%$title%' AND year '%$year%'"
works great!
it's when i try to add year range that messes things up.
how do i write my mysql_query with the year range? :confused:
edit. when year range is used $year will be blank and vice versa
chazzy
02-23-2009, 02:57 PM
WHERE year BETWEEN $from_year AND $to_year
CreativeForce
02-23-2009, 04:34 PM
thanks, but that doesn't really take the other conditions into considerations does it?
i want to merge your query with the existing query "SELECT * FROM mydb WHERE title LIKE '%$title%' AND year '%$year%'"
if i'm not explaining it right ask me and i'll try harder.
please give me suggestions how to solve my little problem.
pollymac
02-23-2009, 04:51 PM
Does that actually work?:
$query="SELECT * FROM mydb WHERE title LIKE '%$title%' AND year '%$year%'"
Anyway, if I'm picking this up right, you want either a title and exact year for a search OR two years (from and to)??
SELECT *
FROM mydb
WHERE (title LIKE '%$title%' AND year '%$year%')
OR (theYear BETWEEN '%$year1%' AND '%$year2%')
Is this any help?
CreativeForce
02-23-2009, 05:33 PM
sorry a little too quick for my own good there.
$query="SELECT * FROM mydb WHERE title LIKE '%$title%' AND year '%$year%'" IS WRONG.
$query="SELECT * FROM mydb WHERE title LIKE '%$title%' AND year LIKE '%$year%'" is correct. thanks :)
about your reply thanks! and yes you're correct that is what i want :)
when $title isset, and $year, $from_year and $to_year is not. it works!
when $year isset, and $title, $from_year and $to_year is not. it works!
when $title and $year isset, and $from_year and $to_year is not. it works!
this is basically what my query does and what i have come so far.
now when i add your part to it. (theYear BETWEEN '%$year1%' AND '%$year2%')
when $title and $from_year and $to_year isset, and $year is not. it KINDA work! (because it returns $titles that are outside of $from_year and $to_year)
i hope i'm making sense for you guys :eek: