Ver Mensaje Individual
  #5 (permalink)  
Antiguo 03/04/2013, 20:58
M3duser
 
Fecha de Ingreso: agosto-2008
Mensajes: 43
Antigüedad: 15 años, 8 meses
Puntos: 1
Respuesta: Problema con UNION

Muchas gracias nuevamente y perdón por las preguntas tan básicas lo que pasa es que soy nuevo en PHP.

Ya lo puse como me dijiste pero aún no logro hacerlo funcionar no se que estará pasando te pongo el código completo a ver si me puedes ayudar perdón tantas moelstias

Código PHP:
Ver original
  1. $db = new mysqli('xxxx', 'xxxx', 'xxxxx', 'xxxxx');
  2.    
  3.     if(!$db) {
  4.        
  5.         echo 'ERROR: Could not connect to the database.';
  6.                
  7.        
  8.     } else {
  9.        
  10.     if(isset($_POST['queryString']))
  11.     {
  12.     $queryString = $db->real_escape_string($_POST['queryString']);
  13.            
  14.     // Is the string length greater than 0?
  15.     if(strlen($queryString) >0) {
  16.        
  17.    $qry =  "SELECT
  18.        Hotel,
  19.        Destino,
  20.        Estado,
  21.        Direccion
  22.    FROM Hoteles
  23.    WHERE
  24.        Hotel  LIKE '%" . $queryString . "%'
  25.        OR  Destino LIKE '%" . $queryString . "%'  
  26.        OR  Estado LIKE '%" . $queryString . "%'
  27.    UNION
  28.    SELECT
  29.        Hotel,
  30.        Destino,
  31.        Estado,
  32.        Direccion
  33.    FROM Pago
  34.    WHERE
  35.        Hotel  LIKE '%" . $queryString . "%'
  36.        OR  Destino LIKE '%" . $queryString . "%'  
  37.        OR  Estado LIKE '%" . $queryString . "%'";
  38.     $query = $db->query($qry);
  39.            
  40.        
  41.            
  42.            
  43.  
  44.  
  45.                
  46.                  
  47.                
  48.                 if($query) {
  49.                     // While there are results loop through them - fetching an Object.
  50.                    
  51.                     // Store the category id
  52.                     $Destino = 1;  
  53.                     $Destino =  htmlentities ($Destino);       
  54.                     while ($result = $query ->fetch_object() ) {
  55.                         if($result->Destino != $Destino) { // check if the category changed
  56.                    
  57.                         echo '<span class="category">'.htmlentities($result->Destino).'</span>';
  58.                        
  59.                        
  60.                             $Destino = $result->Destino;
  61.                                        
  62.  
  63.                         }
  64.                        
  65.                        
  66.                    
  67.                      
  68.                    
  69.                    
  70.                                    
  71.                            $Hotel = $result->Hotel;
  72.                         if(strlen($name) > 35) {
  73.                             $Hotel = substr($Hotel, 0, 35) . "...";
  74.                         }                      
  75.                        
  76.                
  77.                     $HotelCat = $result->Categoria;
  78.                         if(strlen($name) > 35) {
  79.                             $Hotel = substr($Hotel, 0, 35) . "...";
  80.                         }                      
  81.                    
  82.                    
  83.                     echo '<a href="hotelInfo.php?id='.$result->id.'" class="link">';
  84.                
  85.                     echo '<span class="searchheading">'.htmlentities($Hotel).'</span>';
  86.                    
  87.                         $Direccion = $result->Direccion;
  88.                         if(strlen($Direccion) > 40) {
  89.                             $Direccion = substr($Direccion, 0, 40) . "...";
  90.                         }
  91.                
  92.                     echo '<span>'.htmlentities($result->Direccion).'</span></a>';
  93.                    
  94.                    
  95.                    
  96.                    
  97.                     }
  98.                     echo '<span class="seperator"><a href="http://www.ofertaturistica.info" title="Sitemap">Nada interesante? Mapa de Sitio.</a></span><br class="break" />';
  99.                 } else {
  100.                     echo 'ERROR: There was a problem with the query.';
  101.                 }
  102.             } else {
  103.                 // Dont do anything.
  104.             } // There is a queryString.
  105.         } else {
  106.             echo 'There should be no direct access to this script!';
  107.         }
  108.     }