I have a query that just isn't providing results:
$name = "John Smith";
$query = "SELECT * FROM my_table WHERE lname LIKE '%$name%' AND fname LIKE '%$name%'";
lname in the database would be listed as Smith fname in the database would POSSIBLY be listed as John S.
Some entries have a middle initial attached to their name, some don't.
Also, names are pulled in as one string on the page where I am querying this information, not first name and last name strings. Limitation of the existing code.
So I'm trying to search for the last name in the string $name as well as the first name. I assume I'm doing it wrong. Is this possible? Or is there another way to do this?
echo $query;and run it in MySQL directly.John Smithin both thelnameandfnamefields - that's not going to find anything, as the contents are split over both fields.