1 Replies - 1156 Views - Last Post: 08 March 2010 - 11:11 PM Rate Topic: -----

#1 skcin7   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 08-March 10

PHP Search All Words

Posted 08 March 2010 - 11:02 PM

Hello. I am creating PHP/SQL search on my page and I want it to return games that match ALL WORDS of the query string. I have it set up properly, except currently it will return games that match portions of words. For example, the string "M" will return all games that have the character M in them. I only want it to search full words.

This is what my code looks like so far. Currently the code works perfectly except it returns portions of words.

  $words = explode(" ", mysql_real_escape_string(stripslashes($_GET['term'])));
  $SQL_QUERY = "
  SELECT GAMEDB_Games.GameID, GAMEDB_Games.PublisherID, GAMEDB_Games.GameTitle, GAMEDB_Games.ReleaseDate, GAMEDB_Games.RarityC, GAMEDB_Games.RarityI, GAMEDB_Games.RarityB, GAMEDB_Games.ScanCAvailable, GAMEDB_Games.ScanIAvailable, GAMEDB_Games.ScanBAvailable, GAMEDB_Games.RomDownloadAvailable, GAMEDB_Games.RomDownloadID, 
  FROM GAMEDB_Games, GAMEDB_Platform, GAMEDB_Publisher 
    WHERE GAMEDB_Games.PlatformID = GAMEDB_Platform.PlatformID 
    AND GAMEDB_Games.PublisherID = GAMEDB_Publisher.PublisherID ";
  for($i = 1; $i < count($words); $i++) 
    $SQL_QUERY .= "AND GAMEDB_Games.GameTitle LIKE '%$words[$i]%' ";

  $sql = mysql_query($SQL_QUERY);

This post has been edited by skcin7: 08 March 2010 - 11:42 PM

Is This A Good Question/Topic? 0
  • +

Replies To: PHP Search All Words

#2 skcin7   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 4
  • Joined: 08-March 10

Re: PHP Search All Words

Posted 08 March 2010 - 11:11 PM

Actually... after reading over my last post... here is another good question. What is the best way to create a PHP search that will comply with all the regular rules that search engines follow? For example, the string "George Washington -Carver" means search for all entries with George Washington but without the word Carver. Or, the string "(George, Washington)" would mean to find all entries with either the word George or the word Washington. Is this easy or would I have to check for these special cases and parse each string manually?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1