
15/07/2010, 08:14
|
| | Fecha de Ingreso: octubre-2000
Mensajes: 1.692
Antigüedad: 24 años, 4 meses Puntos: 19 | |
Respuesta: Como cargar una grilla Cita:
Iniciado por hidek1 puedes buscar alguna classe.. Te dejo la que hice yo por si te sirve de algo
Código php:
Ver original<?php require_once 'conexion.php'; class databasetable { 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; } }
y el uso
Código php:
Ver original<?php try { $tabla = new databasetable("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"; } ?>
gracias esta muy bueno!!!
__________________ PD: Con amor, fe, amor a Dios y amistad podemos hacer un mundo mejor!!!! |