SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    May 2005
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    which keywords found from search

    not sure how to put it, but let say that I enter a phrase of 4 key words (eg: apple orange banana pine)to search on a column 'text' of a table:
    PHP Code:
    $query "SELECT text FROM books WHERE text ='apple' OR text='orange' OR text='banana' OR text='pine'"
    let say the result yields 10 rows in which any row can have text contain either one of the fruits, a few, or all. My question is, how do we return which row contains which keyword when the result is returned? In most searching function, we return the "text" with the keyword highlighted. I want to do the opposite, I need to display the 4 keywords, and underline anyone of them which "text" contains.

    If we search 1 key word at a time, that can do, but in this case, i have have than 1 phrase to begin with; thus search 1 keyword at a time sounds not a good idea, but not sure if there is any better alternative.

    Thanks.

  2. #2
    SitePoint Enthusiast michelangelo's Avatar
    Join Date
    May 2005
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure I totally understand, but I think you need to add in a search for your primary key, substituting in the primary key column name of course. You might also like to use 'IN' to clean up your code a bit.

    EG:


    PHP Code:
    $query "SELECT primary_key, text FROM books WHERE text IN ('apple','orange','banana','pine'); 


Bookmarks

Posting Permissions

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