Entry
How to search with wildcards from PHP form? MySQL wants %$var% but this doesn't work.
Apr 23rd, 2001 15:37
Shannon Hale, Wyatt James,
I've been able to get this to work by concatenating a string as follows
(assumes that we are getting text from an input called "field"):
...
// Check whether the field was blank, and if not,
// create a where clause in $limit.
if ($field != "") {
$limit = "where myName like '%" . $field ."%'";
}
// Create your query string...
$query = "select myName from myTable " . $limit;
// Connect to the database - snipped...
// This should work...
$records = mysql_query($query)
...
So if the user typed "blah" in the text field, $limit will be "where
myName like '%blah%'".