Ver Mensaje Individual
  #4 (permalink)  
Antiguo 06/06/2018, 13:59
matiri90
 
Fecha de Ingreso: abril-2016
Ubicación: Cordoba
Mensajes: 22
Antigüedad: 8 años
Puntos: 1
Respuesta: Mostrar datos de una tabla mysql con pdo

Tenia errores torpes..

Código PHP:
    function lista($fields$table){
        
$query"
            SELECT
                $fields
            FROM
                $table
        "
;
        
$consulta $this->conexion->query($query);
        
        
$consulta $consulta->fetchAll();
        

        
$rows explode(","$fields);
        
#print_r($rows);
        
$num_rows count($rows);

        
$impresion "<tbody>";

#ACA TENIA UN ERROR.. le agregue un

        
foreach ($consulta as $cons) {
            
$impresion .= "<tr>";
            for(
$i 0$i $num_rows$i++){
                
$impresion .= "<td>".utf8_encode($cons[$rows[$i]])."</td>";
            }
            
$impresion .= "</tr>";
        }
        
$impresion .= "</tbody>";

        try{
            echo 
$impresion;
        }catch(
PDOException $e){
            
print_r($e);
        }
    } 
Muestra todo, ahora el problema es que no me muestra bien la tabla..
Me lo muestra como un string solo..
No me toma los <td>..

Código HTML:
Ver original
  1. <div class="table table-condensed table-striped table-bordered table-hover">
  2.                         <thead>
  3.                             <tr>
  4.                                 <th>CODIGO</th>
  5.                                 <th>NOMBRE</th>
  6.                                 <th>DESC</th>
  7.                                 <th>RUBRO</th>
  8.                                 <th>SUBRUBRO</th>
  9.                                 <th>PRECIO</th>
  10.                                 <th>VENTA</th>
  11.                                 <th>UNIDAD</th>
  12.                                 <th>PROV</th>
  13.                             </tr>
  14.                         </thead>
  15.                         <?php $listado->lista($columnas, "articulo"); ?>