Forum Moderators: coopster

Message Too Old, No Replies

Search by any part of a user name

question

         

savil

6:15 am on Feb 4, 2004 (gmt 0)

10+ Year Member



What should I modify in this script to do a search by any part of a user name and NOT by the whole username:

<?
$rs=@mysql_query("select * from usrinfo where UserName='$username'");
while ($ro=@mysql_fetch_array($rs)){
echo $ro[UserName];
}
?>

Thank You.

tomda

7:07 am on Feb 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not very clear, but try to use the like and % statement. It will check if the string_username are in the username.

e.g., if $string_username is 'bert' then the query will give you 'robert', 'albert' or 'berthe' or whatever with 'bert' in it.

$rs=@mysql_query("select * from usrinfo where UserName LIKE '%$string_username%'");

savil

7:36 am on Feb 4, 2004 (gmt 0)

10+ Year Member



Thank you tomda!
It worked :)