Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2006

    Unanswered: using php to search a database


    I've created a website ( and have added a simple search function to the main page. When given a string it will search the table called news for a string that matches the query using:

    SELECT * FROM news where title LIKE('%$search%') ORDER BY date desc
    what I would like is the search to omit words such as the, and, of, for, if etc and if given a sentence such as 'Gears of War for XBox 360' the search would seperate the main terms (Gears, War, Xbox, 360) and return the relevant results. Could someone give me some help with this and any other help relating to searching a database using php.



  2. #2
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    depending on how big your exclude list is you could use eregireplace to remove any excluded words.... however that approach will not work if you have a large number of words or you want to change that over time (it will be a pig to maintain). So you will need to build a table containing banned words and then do a select for each words parsed out of the incoming parameter)

    consider using the split function to break apart the parameters to indiviusla words

    so the approach would be something like

    split requested parameters into words
    for each word found
    check the word is not on your banned list
    if its not on the banned list add the % to the start & end of each word

    consider using the MySQL match construct rather than LIKE

    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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