how to check one column with multiple strings, please help!

Discussion in 'MySQL' started by free-designer, Jan 14, 2011.

  1. #1
    Hey guys,
    i need a real quick help with something with my db-table

    Well i have a table called meta
    This meta table consists of the the following columns
    • ID
    • meta_key
    • meta_value

    ----------
    Well what i need to do is simple i need to get all meta ids that it's meta_key = status & name
    and at the same time i need to check if the meta_value = active & %the name%

    for more details in words:
    i have an advanced search and the user may search for the data where the status = 'active' And also the name LIKE '%the search%'

    I hope now all people understand my problem.
    please guys help me :) Thanks a lot in advance
     
    free-designer, Jan 14, 2011 IP
  2. free-designer

    free-designer Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    So Guys any suggestions please :) i'll be grateful ?
     
    free-designer, Jan 22, 2011 IP
  3. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #3
    Is this you were looking for?
    SELECT * FROM meta
    WHERE (meta_key = 'status' AND meta_value = 'active') OR 
    (meta_key = 'name' AND meta_value LIKE '%the name%')
    Code (markup):
     
    mwasif, Jan 22, 2011 IP
  4. free-designer

    free-designer Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Well it's a little bit near, but the problem is that in your query, you are saying if you found any meta_key = status and meta_value = 'active' get them if you didn't found any results with that just get the meta_key = 'name' AND meta_value LIKE '%the name%'

    i don't want it to check if that there get otherwise get the second one, no i want it to look for both to get me all the rows that it's meta_key = status and name ,,, and all rows that is meta_value = active and LIKE '%the name%'.

    sorry thats not what i need :) do you have any other suggestions in your mind.
     
    free-designer, Jan 22, 2011 IP
  5. mwasif

    mwasif Active Member

    Messages:
    816
    Likes Received:
    23
    Best Answers:
    1
    Trophy Points:
    70
    #5
    Did you try to change this query according to your requirements?
     
    mwasif, Jan 22, 2011 IP
  6. free-designer

    free-designer Peon

    Messages:
    79
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Well, I've got the idea of the meta from wordpress. it make things much cooler, i mean instead of doing it with a looooot of columns at one place you can do it with meta meaning that you can have the id referring to the item and the meta_key and meta_value, but my script will have an advanced search it will be like the user can select more than one item to get his desired content.

    like
    ---------------------------
    search:
    Status: will be select box
    name: will be input

    ---------------------------

    if you where were me and you have this meta thing in the database, how would you write your query to get the right result?
     
    free-designer, Jan 22, 2011 IP