Search String in a Field

Discussion in 'PHP' started by MikeLiao, Oct 13, 2008.

  1. #1
    If I have a field named : fruits
    with the following record: apple, banana, mango, melon

    How can do a query / loop to extract individual fruit?
    And a query that will search a fruit, let say I just want to search if mango exist.

    Thanks
     
    MikeLiao, Oct 13, 2008 IP
  2. edual200

    edual200 Active Member

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #2
    whats the table name fruits or something else? whats the field name?

    suppose the field name is fruits then

    select fruits from tablename ( would be for all the of them)
    select fruits from tablename where fruits = mango ( for the mango )

    those are assuming you dont need anything else from the table other then the fruit name?
     
    edual200, Oct 13, 2008 IP
  3. MikeLiao

    MikeLiao Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Sorry for the confusion but
    apple, banana, mango, melon is just a single record (meaning 1 record could have many fruit name)

    So my question is how can I search for the all records (rows) with mango in it?
     
    MikeLiao, Oct 13, 2008 IP
  4. edual200

    edual200 Active Member

    Messages:
    309
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #4
    you would use like %mango%
    SELECT * FROM `tablename` WHERE `fruits` LIKE %mango%
     
    edual200, Oct 13, 2008 IP
  5. MikeLiao

    MikeLiao Peon

    Messages:
    43
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I need and exact match. If I have a record apple, banana, mango, watermelon
    It will return true because it will see the watermelon. What I need is the function (or whatever) that will "segregate" the fruits and then see if there is an exact match.
     
    MikeLiao, Oct 13, 2008 IP
  6. javaongsan

    javaongsan Well-Known Member

    Messages:
    1,054
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    128
    #6
    $Indfruit=explode(",",$fruits)
    for($i=1; $i < sizeof($Indfruit); $i++)
    {
    if ($Indfruit == "mango")
    break;
    }
     
    javaongsan, Oct 13, 2008 IP