techker Posted September 9, 2012 Share Posted September 9, 2012 Hey guys i have a form that shows the full name of a student. like student : Micheal Jackson i need to search the database for that student. but my tables have first name and last name so the issue i have is i got the full name when in my database i have 2 columns first and last name... so in phpmyadmin i tried the search tab. so i pasted the full name in first and tried LIKE-LIKE%% =.... but nothing worked?? Quote Link to comment https://forums.phpfreaks.com/topic/268189-search-with-full-name/ Share on other sites More sharing options...
Barand Posted September 9, 2012 Share Posted September 9, 2012 ... WHERE INSTR('Michael Jackson', firstname) AND INSTR('Michael Jackson', lastname) Quote Link to comment https://forums.phpfreaks.com/topic/268189-search-with-full-name/#findComment-1376505 Share on other sites More sharing options...
techker Posted September 9, 2012 Author Share Posted September 9, 2012 wow!impressive.what is the instr called so i can look it up? Quote Link to comment https://forums.phpfreaks.com/topic/268189-search-with-full-name/#findComment-1376507 Share on other sites More sharing options...
Barand Posted September 9, 2012 Share Posted September 9, 2012 http://dev.mysql.com/doc/refman/5.6/en/string-functions.html#function_instr Quote Link to comment https://forums.phpfreaks.com/topic/268189-search-with-full-name/#findComment-1376510 Share on other sites More sharing options...
PFMaBiSmAd Posted September 9, 2012 Share Posted September 9, 2012 Hopefully, Michael's brother, Jackson Jackson isn't a student too, because that will match him. Also, their distant cousin Jackson Michael and his brother Michael Michael, and other first/last names that can be used as either - Martin Davis, Thomas Martin, Scott Thomas, ... I would concatenate the fields - CONCAT_WS(' ',firstname,lastname) = 'Michael Jackson' Quote Link to comment https://forums.phpfreaks.com/topic/268189-search-with-full-name/#findComment-1376512 Share on other sites More sharing options...
Barand Posted September 9, 2012 Share Posted September 9, 2012 And there could also be multiple Michael Jacksons too, but that's always a problem matching name strings and not numeric ids Quote Link to comment https://forums.phpfreaks.com/topic/268189-search-with-full-name/#findComment-1376513 Share on other sites More sharing options...
techker Posted September 9, 2012 Author Share Posted September 9, 2012 i like! the first one you gave me works good.it's exactly what i needed.i want to read up on this abit.thx Quote Link to comment https://forums.phpfreaks.com/topic/268189-search-with-full-name/#findComment-1376527 Share on other sites More sharing options...
Barand Posted September 9, 2012 Share Posted September 9, 2012 PFMs is the better solution for the reasons he gave. Quote Link to comment https://forums.phpfreaks.com/topic/268189-search-with-full-name/#findComment-1376529 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.