www.webdeveloper.com
Results 1 to 5 of 5

Thread: mysql_query

  1. #1
    Join Date
    Oct 2004
    Posts
    22

    mysql_query

    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?

    edit. when year range is used $year will be blank and vice versa

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    WHERE year BETWEEN $from_year AND $to_year

  3. #3
    Join Date
    Oct 2004
    Posts
    22
    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.

  4. #4
    Join Date
    Jul 2008
    Location
    Carnoustie, Scotland
    Posts
    36
    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)??

    Code:
    SELECT * 
    FROM mydb 
    WHERE (title LIKE '%$title%' AND year '%$year%') 
    OR (theYear BETWEEN '%$year1%' AND '%$year2%')
    Is this any help?

  5. #5
    Join Date
    Oct 2004
    Posts
    22
    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles