...

View Full Version : Question about SEARCHING - Searching Any Word



skcin7
09-01-2009, 07:40 PM
Hello. I am building an advanced search feature on my website. The way I am designing it is to allow 3 different types of searches: Any Words, Any Portion of a Word, and Exact Phrase.

This is how I do exact phrase:

$sql = mysql_query("select * from gamesdb where search_keywords like '$term_sanitized' ");

This is how I do Any Portion of a Word: (Same as above except I added the wildcard '%' symbols)

$sql = mysql_query("select * from gamesdb where search_keywords like '%$term_sanitized%' ");

My question is: how can you search for full words only? For example, if the name "John Smith" is in my database, I want that entry to display if the user searches for 'John', 'Smith', or 'John Smith', but NOT if he searches for a portion of it, something like 'Joh' or 'ith'.

Thank you in advance for your help!

seco
09-01-2009, 10:24 PM
remove the front % or back % from the wildcard. Play with that see if it works.

skcin7
09-02-2009, 06:05 AM
Hi thanks for the reply. I have been messing with it for a while, which is why I posted my question here. I currently have a functional search bar, however it is not how I want it.

What I want, is to only show entries that match a full word that the user entered. For example, searching "Mario" will return "Super Mario 2" and similar entries. Similarly, searching "Super 2" will return "Super Mario 2" and similar entries. However, searching "Mar" will return nothing.

I've seriously been messing with it all day today and searching Google but I am very much new to PHP and SQL and I just can't figure it out. I imagine the solution is quite simple. Thanks in advance for any more help provided.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum