Jump to content

Search by entry


user4fun

Recommended Posts

I know i have asked this before, but there are some changes that i am trying to makeform : input type text and name is "word"in the select querythe sql table have a column with several words in it seperated by spacesexampledesigner happy valentine stuff [all those words in one column called IDTAG

$result = mysql_query("SELECT * FROM Mytable WHERE IDTAG LIKE '%{$word}%'");

The above select statment is too general, how can i make it more specific,i dont want the result to show up if $words = hbut i would like it to show up if the $word is equal to happy

Link to comment
Share on other sites

You can put spaces around the word if you want to make sure that it only matches an entire word, but you will also need to make sure that the first word in the field has a space before it and the last word has a space after it.

Link to comment
Share on other sites

Yeah, just a space.

$result = mysql_query("SELECT * FROM Mytable WHERE IDTAG LIKE '% {$word} %'");

You just need to make sure that the value in the field is also surrounded by spaces. So instead of storing this in the database:

'designer happy valentine stuff'

you need to store this:

' designer happy valentine stuff '

So if you have this in the database:

' day birthday '

then if the query looks like this (note the spaces):

$result = mysql_query("SELECT * FROM Mytable WHERE IDTAG LIKE '% day %'");

it will match the word "day" (because it has spaces around it), but not "birthday" (because the "day" in "birthday" does not have a space before it).

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...