我正在制作PM系统。
在收件人字段中,如果您输入
Fox
它会回归:你的意思是梅根福克斯?
但是,如果Megan的名字不仅仅是“Fox”,那么它只会询问你是否只指其中一个。
如果姓氏“Fox”的数量超过1,那么我希望它能说:
Who did you mean?
Pammy Fox
Megan Fox
如果只有1的姓氏,我希望它只是说
Did you mean Megan Fox?
(就像现在一样)
我该怎么做?
这是我的代码:
$qur = mysql_query("
SELECT id, firstname, lastname,
(firstname = '$firstname' AND lastname = '$lastname') AS full FROM users
WHERE (firstname = '$firstname' AND lastname='$lastname')
OR (firstname LIKE '$firstname%' AND lastname LIKE '$lastname%')
OR firstname LIKE '$firstname%' OR lastname LIKE '$firstname%'
ORDER BY (firstname = '$firstname' AND lastname='$lastname') DESC");
$get = mysql_fetch_array($qur);
if($get["full"] == 1){
echo $get["id"];
}else{
echo "Did you mean: ".$get["firstname"]." ".$get["lastname"]." ?";
}
答案 0 :(得分:1)
使用mysql_num_rows($result)
答案 1 :(得分:1)
while($get = mysql_fetch_array($qur)) {
$name[] = $get["firstname"]." ".$get["lastname"];
}
if(count($name) > 1) {
echo 'Who did you mean?<br/>';
} else {
echo 'Did you mean ';
}
echo implode('<br/>', $name);
答案 2 :(得分:0)
while($get = mysql_fetch_array($qur) {
//do your stuff
}
我想无论如何,自从我使用PHP与PHP
以来已经很久了