Bu daha basit hale getirmek / daha hızlı

0 Cevap

Bu sorgu daha hızlı yapmak için bir yolu var mı:

$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");

Ben bu ne gerek:

Check if its a full match.
Get firstname lastname
Being able to only enter lastname "Fox" and let it find the firstname (get all users with lastname Fox, and show their firstname too and display check the script at bottom.)
Being able to only enter the firstname "Megan" and let it find the lastname (^)
Being able to only enter Megan F, and let it show "Megan Fox"
Being able to only enter Me Fox, and let it show "Megan Fox"

Bu hiçbir sorun olmadan çalışan, bana ne olduğunu. Belki kullanıcıların çok çalıştırdığınızda bu yavaş çalışır düşünüyorum rağmen

Ben bu ile istimal:

 if (mysql_num_rows($qur) == 1) {

 $get = mysql_fetch_array($qur);
    if($get["full"] == 1){
    echo $get["id"];
    }else{
     echo "Did you mean: ".$get["firstname"]." ".$get["lastname"]." ?";
    }
 }elseif(mysql_num_rows($qur) > 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);

 } 

0 Cevap