Thread: MySQL QUERY

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Posts
    3
    Rep Power
    0
    Hello,
    I have a huge problem with an sql query. I have been working on this now for about one week and cant get it solved.
    The following query doesnot work, well, it does not cause and error but its not working how i want it to.

    $query = "SELECT * FROM links WHERE (name LIKE '%" . $search . "%' OR link LIKE '%" . $search . "%' OR besch LIKE '%" . $search . "%' OR keyword LIKE '%" . $search . "%') AND (active = 1)";

    So, this query is supposed to search in a database for a certain keyword. It works almost quite fine. Here are the problems: The query doesnot care wether active is one or anything else. Second: The query doesnot search in "besch". If the keyword is in "besch" and nowhere else the records doesnot get selected. Anyone an idea how to handle this?! I am getting really frustrated with this... I think I put all the ANDs and ORs in wrong order...

    [This message has been edited by starspider (edited May 24, 2000).]
  2. #2
  3. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    try the following:

    $query="Select * from links where (name like "%$search%" or link like "%$search%" or besch like "%$search%" or keyword like "%$search%") AND (active = 1)";

    if active is varchar then use active='1'




    ------------------
    SR -
    shiju.dreamcenter.net

    "The fear of the LORD is the beginning of knowledge..."

Similar Threads

  1. MySQL COUNT query - help needed please.
    By rycrostud in forum MySQL Help
    Replies: 1
    Last Post: August 29th, 2003, 09:33 AM
  2. Efficient way to query MySQL
    By kingmike in forum PHP Development
    Replies: 7
    Last Post: July 30th, 2002, 04:19 PM
  3. Need help with a mysql query
    By mrdon in forum MySQL Help
    Replies: 3
    Last Post: July 23rd, 2002, 05:22 PM
  4. Replies: 2
    Last Post: July 22nd, 2002, 02:23 PM
  5. Can't get most recent date from MySQL query
    By jpluttme in forum MySQL Help
    Replies: 4
    Last Post: October 9th, 2001, 01:27 AM

IMN logo majestic logo threadwatch logo seochat tools logo