开发者

Tricky MySQL search

I've got 2 varchar columns, one for开发者_StackOverflow the first name, and one for last name.

I'm trying to create a search box where the user will either type the first name or last name of a person, and it would search accordingly and show results. I.e he could either put in 'john' or 'john smith'.

How can I achieve this? Is there a foolproof way to seperate the first and last name from the user typed data (i.e, what if he typed Anne Marie Smith, which would I use as the first name and which as the last?).


Do it the other way. Concatenate the first name and last name from your database table (ie, "Anne Marie" + "Smith" -> "Anne Marie Smith") and search against that.


select CONCAT(first_name,last_name) as full_name from user where full_name like "%$token";

here $token = $_GET['token'];

i.e whatever user type in the search box you can get by using ajax .

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜