I need to enable users of my membership database to query the database and identify other members meeting some criteria. The following code snippet with hard coded search criteria works well:
// $searchfield = "street_name";
// $searchterm = "Greystone Drive";
$sql = 'SELECT * '
. ' FROM `residents` '
. ' WHERE street_name LIKE "Greystone Drive" ORDER BY street_no';
All of the pertinent records are found and ordered appropriately.
Removing the comments from the code results in no items found:
$searchfield = "street_name";
$searchterm = "Greystone Drive";
$sql = 'SELECT * '
. ' FROM `residents` '
. ' WHERE $searchfield LIKE $searchterm ORDER BY street_no';
It seems as though this should work but I'm obviously doing something wrong. All suggestions are appriciated.
Thanks.


LinkBack URL
About LinkBacks



Reply With Quote
And it still works if you remove the wildcards:


Bookmarks