title: search query order by asc or desc
body: <p>Hi what's the best way to do a 'order by' from a query without executing a query for another time? Lets say I have a search query when I have to find names or surnames using a form ,an example :</p>
  
  <pre><code>     //Array for storing WHERE part of query
     $where=array();  
  
     if(!empty($name)) AND !empty($surname)){
           $where[]="Name LIKE '%$name%'" .
              "AND Surname LIKE '%$surname%'";
     }
     elseif(!empty($name)){
          $where[]="Name LIKE '%$name%'";
     }
     elseif(!empty($surname)){
         $where[]="Surname LIKE '%$surname%'";
     }
  
     $where = implode(' AND ', $where);
  
     $sql="SELECT Name,Surname FROM TABLE WHERE $where ORDER BY Name DESC";
  
     $res = mysql_query($sql);
  
     while ($row = mysql_fetch_array($res, MYSQL_NUM)) {
             $name    = $row[0];
             $surname    = $row[1];
             echo"$name";
             echo"$surname";
  
  
      }
  </code></pre>
  
  <p>How can I display Name or Surname in ASC mode(ORDER BY Name ASC) after my search"Name LIKE %surname%",without executing again the SQL query? I want for example when I search for a name containing "ich"word to have a list in this way:</p>
  
  <pre><code>  MICHAEL
    PICHAEL
    XICHAEL
      =&gt; the ASC mode
    XICHAEL
    PICHAEL
    MICHAEL
     =&gt; the DESC mode
  </code></pre>