Ver Mensaje Individual
  #4 (permalink)  
Antiguo 27/02/2015, 14:33
Avatar de informacionsys
informacionsys
 
Fecha de Ingreso: mayo-2011
Ubicación: Bogota D.C
Mensajes: 793
Antigüedad: 13 años
Puntos: 76
Respuesta: Traer a una tabla los campos en forma de filas.

seria algo como :


Código PHP:
Ver original
  1. $con = mysql_connect("xxxx","xxxxx");
  2. mysql_select_db("midb",$con);
  3.  
  4. $campos = array();
  5. $resultSet = mysql_query("SELECT * FROM mitabla LIMIT 0,1");
  6.  
  7. if(mysql_num_rows($resultSet) > 0)
  8. {
  9.     $fila      = mysql_fetch_assoc($resultSet);
  10.     $campos    = array_values(array_keys($fila));  
  11. }
  12.    
  13. if(!empty($campos))
  14. {
  15.     $comparacion = "";//tu valor
  16.     $html  =  '<table border=1px>';
  17.     $html .= '<tr><td>CAMPO </td><td>VALOR</td></tr>';
  18.  
  19.     foreach($campos as $camp)
  20.     {
  21.  
  22.         $query  = sprintf("SELECT (%s) AS total FROM mitabla WHERE %s = '%s' ",$camp,$camp,$comparacion);
  23.         $result = mysql_query($query);    
  24.         $row    = mysql_fetch_assoc($result);
  25.  
  26.         if(mysql_num_rows($result) > 0)
  27.         {
  28.             $html .= '<tr><td>'.$camp.'</td> <td>'.$row["total"].'</td></tr>';
  29.         }
  30.     };//fin foreach
  31.  
  32.     $html .=  '</table>';
  33.  
  34.     echo $html;
  35.  
  36. }

lo hice ahi rapido; posiblemente alla algun error de sintaxis...espero te haya entendido

Última edición por informacionsys; 27/02/2015 a las 14:49