trouble with MySQL 'LIKE' command
| From: | r.gelstharp | Date: | Fri, 04 May 2001 18:00:25 +0000 |
| Subject: | trouble with MySQL 'LIKE' command | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-7288@lists.php.net to get a copy of this message | ||
I'm trying to implement a search on my site. When the user enters a search
string and pressed the Search button it sends the search string into a
cariable I call searchfor, and I then construct a query that goes something
like :
"SELECT <whatever> FROM <a table> WHERE product_name LIKE $searchfor.....
now I know there are things you can do with LIKE such as '%' to search for
an arbitrary number of characters before or after the search string.
'WHERE product_name LIKE '%$searchfor%'....'
this has been causing me problems by outputting mostly rubbish, and then I
find out that the '$' is used in the LIKE command for matching characters
too.
How do I construct a SELECT statement that uses a PHP variable in the LIKE
clause?