la otra ves estaba haciendo una class para eso.. aun no esta lista pero para que te des una idea
Código PHP:
Ver original<?php
require_once 'Conexion.php';
class DatabaseTables
{
private $consulta;
private $matriz;
private $tabla;
public function __construct($consulta)
{
$this->consulta = $consulta;
}else {
Throw new Exception("El parametro debe ser una consulta SQL válida");
}
$this->verificarDatos();
}
private function verificarDatos()
{
$db = new Conexion();
$matriz = $db->query($this->consulta);
$this->matriz = $matriz->fetchAll(PDO::FETCH_ASSOC);
}else {
Throw new Exception("La consulta presenta errores");
}
}
public function generateTable()
{
$contador = -1;
$enum = 1;
$this->tabla .= "<table>";
foreach($this->matriz as $fila => $celdas) {
$this->tabla .= $contador < 0 ? "<tr><td>#</td>" : "<tr><td>$enum</td>";
foreach($celdas as $columna => $celda) {
if(++$contador < 1) {
foreach($ncols as $ncol) $this->tabla .= "<th>$ncol</th>";
$this->tabla .= "</tr><tr><td>$enum</td>";
}
$this->tabla .= "<td>$celda</td>";
}
$this->tabla .= "</tr>";
$enum++;
}
$this->tabla .= "</table>";
return $this->tabla;
}
}
?>
<style type="text/css">
*{font-size:11px;font-family:fantasy;}
tr th,td:first-child{background-image:url("../resources/images/gradient.gif");font-weight:bold;color:#555;text-shadow:1px 1px white;}
td{color:#666;}
td,th{padding:5px;empty-cells:show;border:1px solid #999;}
table{border-collapse:collapse;}
</style>
<?php
try {
$tabla = new DatabaseTables("SELECT * FROM db_editor");
echo $tabla->generateTable();
}catch(Exception $e) {
echo " - Warning (" . $e->getCode() . ") [" . pathinfo($e->getFile(), PATHINFO_BASENAME
) . "::" . $e->getLine() . "] " . $e->getMessage() . "<br />\n"; }
?>