I would like to make "Search you'r LOGIN" like in facebook :
Eg. searching for "Stock Overflow" would return
Stack Overflow
SharePoint Overflow
Math Overflow
Politic Overflow
VFX Overflow
Eg. searching for "LO" would return:
pabLO picasso
michelangeLO
jackson polLOck
Eg. searching for username "user123" would return :
user123
user1234
and etc ...
My Database rows :
userid | username | useremail | user_fname | user_lname
I would like to make a search input that search the word in any of this rows like above examples,
Here my php till now :
$string = $purifier->purify(@$_POST['string']);
$query = "SELECT * FROM users WHERE user_fname = '".$string."' OR user_lname = '".$string."' OR username = '".$string."' OR useremail= '".$string."'";
mysql_query("SET NAMES 'utf8'");
$result2 = mysql_query($query);
$num = mysql_num_rows($result2);
if($num == 1)
{
//true
}else{
//not found nothing
}
this way is not working good , and its not return all the similar reuslts of the word that i put in search input. plus how i return it with foreach if there is more then 1 similar result ?
Thanks allot.
Update :
Thanks all , my updated code to fix it :
$query = "SELECT * FROM users WHERE user_fname like '%".$string."%' OR user_lname like '%".$string."%' OR username like '%".$string."%' OR useremail like '%".$string."%'";
and i am not using mysql , just for the examples i had more easy to do like this..