简体   繁体   English

PHP:如果有多个名称

[英]PHP: If more than one name

Im making a PM system. 我正在制作PM系统。

In the recipient field, if you enter 在收件人字段中,如果输入

Fox

It will return: Did you mean Megan Fox? 它会回归:你的意思是梅根福克斯?

But what if there is more than Megan, having lastname "Fox", then it will only ask if you meant only one of them. 但是,如果有超过梅根,有姓“福克斯”,那么它只会询问你是否只指其中一个。

If there's more than 1 with lastname "Fox" then i wish it to say: 如果姓氏“ Fox”超过1,则希望它说:

Who did you mean?
Pammy Fox
Megan Fox

And if there only is 1 with that lastname, i wish it to just say 如果只有1个姓氏,我希望它只是说

Did you mean Megan Fox?

(like it does now) (就像现在一样)

How can i do that? 我怎样才能做到这一点?

here's my code: 这是我的代码:

$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"]." ?";
 }

use mysql_num_rows($result) 使用mysql_num_rows($result)

link 链接

   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);
while($get = mysql_fetch_array($qur) {
    //do your stuff
}

I think anyway, been a long time since I've used mysql with PHP 我想无论如何,自从我将mysql与PHP结合使用以来已有很长时间了

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM