0

我需要知道如何显示类似的搜索查询用户名,例如是否有用户名:johnhol、_john_、donjohnqq、king_john、code_john,如果我们搜索 john,则所有以 john 开头的名称必须显示当前 iam using

$result = mysql_Query("SELECT user FROM UserData WHERE user LIKE '%$username%'") or die(mysql_error());
$fetch = mysql_num_rows($result);

但它不像我所说的那样显示,它只显示一些名称,如 _john_ , king_john 之类的名称仅根据代码显示,所以请告诉我如何使用搜索查询进行搜索并显示 mysql 数据库中的所有起始名称。

4

1 回答 1

0

I *THINK* you are looking for everything which starts with $username. Is that correct? If so, then your query should only have one % at the end:

SELECT user FROM UserData WHERE user LIKE '$username%'

That will match john_glenn but not glenn_johnson.

于 2012-10-10T19:15:51.727 回答