Ver Mensaje Individual
  #3 (permalink)  
Antiguo 06/10/2009, 13:44
samu22
 
Fecha de Ingreso: abril-2008
Mensajes: 453
Antigüedad: 16 años, 1 mes
Puntos: 16
Respuesta: If en AutoSuggest

proba con algo asi
Código php:
Ver original
  1. <?php    
  2.     // PHP5 Implementation - uses MySQLi.
  3.     // mysqli('localhost', 'yourUsername', 'yourPassword', 'yourDatabase');
  4.     $db = new mysqli(DB_SERVER,DB_USER,DB_PASS,DB_NAME);
  5.    
  6.     if(!$db) {
  7.         // Show error if we cannot connect.
  8.         echo 'ERROR: Could not connect to the database.';
  9.     } else {
  10.         // Is there a posted query string?
  11.         if(isset($_POST['queryString'])) {
  12.             $queryString = $db->real_escape_string($_POST['queryString']);
  13.            
  14.             // Is the string length greater than 0?
  15.            
  16.             if(strlen($queryString) >0) {
  17.                 // Run the query: We use LIKE '$queryString%'
  18.                 // YOU NEED TO ALTER THE QUERY TO MATCH YOUR DATABASE.
  19.                 // eg: SELECT yourColumnName FROM yourTable WHERE yourColumnName LIKE '$queryString%' LIMIT 10
  20.                
  21.                 $query = $db->query("SELECT * FROM pro WHERE pn LIKE '$queryString%' LIMIT 15");
  22.                 if($query) {
  23.                     // While there are results loop through them - fetching an Object (i like PHP5 btw!).
  24.                     $num = $query->num_rows;
  25.                     if($num>0){
  26.                         while ($result = $query ->fetch_object()) {
  27.                             // Format the results, im using <li> for the list, you can change it.
  28.                             // The onClick function fills the textbox with the result.
  29.                            
  30.                             // YOU MUST CHANGE: $result->value to $result->your_column
  31.                             // AutoFill Search Field:
  32.                              echo '<li><a href="search.php?Search='.$result->part.'">'.$result->part.'</a></li>';
  33.                          }
  34.                     }else{
  35.                         echo 'No encontrado, por favor contactanos';
  36.                 } else {
  37.                     echo 'ERROR: There was a problem with the query.';
  38.                 }
  39.             } else {
  40.                 // Dont do anything.
  41.             } // There is a queryString.
  42.         } else {
  43.             echo 'There should be no direct access to this script!';
  44.         }
  45.     }
  46. ?>

le agregue un num_rows para saber si la consulta devuelve un numero mayor a 0 en el caso contrario mandara el mensaje