Ver Mensaje Individual
  #8 (permalink)  
Antiguo 03/09/2015, 12:12
mblascog
 
Fecha de Ingreso: enero-2002
Ubicación: Sabadell
Mensajes: 565
Antigüedad: 22 años, 4 meses
Puntos: 4
Respuesta: Recibir un array en function (data)

Buenas,
Te pongo el código para que veas:

Código Javascript:
Ver original
  1. $.post("<?php echo URL.'includes/inc_getImmobles.php'?>", {prm:prmTipus+"-"+prmCiutat+"-"+prmPreu+"-"+prmHabitacions+"-"+prmMetres+"-"+prmOrdre+"-"+prmDireccio+"-"+prmBarris}, function(data){
  2.                 $("#contingut").html(data.immobles);
  3.                 $("#totalTrobats").html("TROBATS " + data.total);
  4.             },"json");


Código PHP:
Ver original
  1. <?php
  2.     $parametres = $_REQUEST["prm"];
  3.     $arrPrm = explode('-', $parametres);
  4.     $tipus = $arrPrm[0];
  5.     $ciutat = $arrPrm[1];
  6.     $preu = $arrPrm[2];
  7.     $habitacions = $arrPrm[3];
  8.     $metres = $arrPrm[4];
  9.     $ordre = $arrPrm[5];
  10.     $direccio = $arrPrm[6];
  11.     $zones = $arrPrm[7];
  12.  
  13.     include("inc_config.php");
  14.     include("inc_connexio.php");
  15.        
  16.     $condicions = "";
  17.     if ($tipus != "")
  18.         $condicions = $tipus;
  19.  
  20.     if ($ciutat != "") {
  21.         if ($condicions != "")
  22.             $condicions .= " AND ";
  23.         $condicions .= $ciutat;
  24.     }  
  25.  
  26.     if ($preu != "") {
  27.         if ($condicions != "")
  28.             $condicions .= " AND ";
  29.         $condicions .= $preu;
  30.     }
  31.    
  32.     if ($habitacions != "") {
  33.         if ($condicions != "")
  34.             $condicions .= " AND ";
  35.         $condicions .= $habitacions;
  36.     }
  37.    
  38.     if ($metres != "") {
  39.         if ($condicions != "")
  40.             $condicions .= " AND ";
  41.         $condicions .= $metres;
  42.     }
  43.        
  44.     if ($zones != "") {
  45.         if ($condicions != "")
  46.             $condicions .= " AND ";
  47.         $condicions .= $zones;
  48.     }
  49.                
  50.     if ($ordre == "")
  51.         $ordenat = "";
  52.     else {
  53.         if ($ordre == "Preu")
  54.             $ordenat = " ORDER BY precio";
  55.         else if ($ordre == "M2")
  56.             $ordenat = " ORDER BY metros";
  57.         else if ($ordre == "Habitacions")
  58.             $ordenat = " ORDER BY habitaciones";
  59.         else
  60.             $ordenat = " ORDER BY nombre_poblacion";
  61.     if ($direccio == "D")
  62.         $ordenat .= " DESC";
  63.     }  
  64.        
  65.  
  66.     $consulta = "SELECT U.referencia, U.familia, U.situacion1, U.precio, U.metros, U.habitaciones, U.CodigoPostal, P.nombre_poblacion, F.foto, E.titulo, E.descripcion
  67.              FROM t_un U
  68.              LEFT JOIN t_fotos F ON U.referencia = F.referencia
  69.              INNER JOIN t_es E ON U.id_piso = E.id_piso
  70.              INNER JOIN t_poblacion P ON u.poblacion = P.id_poblacion
  71.              WHERE ".$condicions."
  72.              GROUP BY U.referencia";
  73.     $qSelect =  mysql_query($consulta);
  74.     $registres = mysql_num_rows($qSelect);
  75.  
  76.     if ($registres > 0){
  77.         $retorn = "<table id='taulaContingut'>";
  78.         while ($fila = mysql_fetch_assoc($qSelect)) {
  79.             $retorn .= "<tr class='filaContingut'>
  80.                 <td class='columnaContingut' id='columnaContingut'><a href=''><img src=".URL."fincamps_HS/".$fila['foto']."></a></td>
  81.                 <td class='columnaContingut'><a href=''><span><p>".$fila['situacion1']." - ".$fila['titulo'].'(ref. '.$fila['referencia'].')</p></span><p>'.
  82.                 number_format($fila['precio'], 2, ',','.')."€ - ".
  83.                 $fila['metros'].'m² - ';
  84.             if ($fila['habitaciones'] != "0")
  85.                 $retorn .= $fila['habitaciones'].' habs. - ';
  86.             $retorn .= $fila['nombre_poblacion']."</p>".$fila["descripcion"]."</a></td></tr>";
  87.         }
  88.         $retorn .= "</table>";
  89.     }
  90.     echo json_encode(array("immobles"=>$retorn, "total"=>$registres));
  91. ?>

He pensado que no fuera porqué el contenido de la variable $retorn fuera muy grande, y lo he probado así:

Código PHP:
Ver original
  1. echo json_encode(array("immobles"=>"aaa", "total"=>"bbb"));
Y tampoco devuelve nada

Creo que el problema lo tengo con json_encode, pero he mirado por Internet y el manual y no sé ver nada.

Gracias
__________________
Qué fácil cuando lo sabes y qué difícil cuando no