I have database that contains first and last names in separate columns. I have a live search that currently searches first OR last names, but not a full name. My current query is: SELECT id, fname, lname, sport,state, school FROM coach WHERE lname LIKE '%$query%' OR fname LIKE '%$query%' LIMIT 5 Code (markup): How do go about searching for a full name? For instance if someone types "Bob Smith" right now nothing would be returned because there is no first or last name of "Bob Smith", but there is a person with the first name Bob and the last name Smith
Try this , SELECT id, fname, lname, sport,state, school FROM coach WHERE CONCAT(fname, "", lname) LIKE '%$query%' LIMIT 5
Create a FULL TEXT index on both columns - first and last name. It will work far better than LIKE statement. FULL TEXT index can be created only for MyISAM tables