【发布时间】:2009-12-03 10:28:39
【问题描述】:
我需要实现以下功能:
我有一个包含姓名和姓氏的姓名字段。这存储在数据库中,并按“姓氏”的顺序排列。
我正在实现一个搜索这些记录的脚本。目前,我设法检查一个字符串是否包含一个空格,如果它包含一个空格,则意味着它是一个名字而不是一个 ID 卡号。代码如下:
$query = "John Doe";
$checkIfSpaceExists = strpos($query, " ");
if ($checkIfSpaceExists == "")
{
//No Space therefore it is not a name
}
else
{
//Contains space
$queryExploded = explode(" ", $query);
foreach ($queryExploded as $q)
{
//Here I need the functionality so that if someone entered John Doe
//2 different strings are saved, which are
//$string1 = John Doe
//$string2 = Doe Johns
//If the name consists of 3 parts, strings for every combination is saved
}
然后我将这些字符串插入到带有 LIKE 属性的 SQL 语句中,JOHN DOE 和 DOE JOHN 都会有一个 LIKE。因此,如果用户可以输入 John Doe 或 Doe John 来查找结果。
关于如何做到这一点的任何建议?
非常感谢
克里斯
【问题讨论】: