parece que este solo vino a presumir, aca tengo una mas avanzada a ver que opinan:
al estilo de una BD
Código PHP:
<?php
class GnTabla extends MySQL {
private $col = array();
public $auto_increment = 1; //valor por default
public $col_sum = array();
public $class_status = 'on'; //valor por default
public $class_func;
function __construct($class) {
$new_class = ($class != '') ? " class=\"$class\"" : '';
echo "<table$new_class>\n";
}
public function Type($Type) { //difined type
foreach($Type as $key => $value) {
$this->col[$key]['Type'] = $value;
}
}
public function Name($Name) { //defined value
foreach($Name as $key => $value) {
$this->col[$key]['Name'] = $value;
}
}
private function PutOrderCol() {
ksort($this->col); //put in order the array
}
public function TQuery($query) {
parent::__construct();
parent::Query($query);
@parent::error();
}
public function Display() {
$this->PutOrderCol();
echo " <tbody>\n";
while($datos = parent::fetch_assoc()) {
if($this->class_status != 'off') {
$class = ' class="'; //start
if(empty($this->class_func)) {
$class .= $class_name = ($class_name == 'even') ? 'odd' : 'even';//even and odd have to be style defined
} else {
foreach($this->class_func['P'] as $col_name) {
$c_parameter[] = $datos[$col_name];
}
$class .= $class_name = call_user_func_array($this->class_func['N'], $c_parameter);
}
$class .= '"';
}
echo " <tr$class>\n";
foreach($this->col as $COL) {
echo ' <td>';
if(!is_array($COL['Name'])) {
if($COL['Type'] == 'Text' or empty($COL['Type'])) {
echo $datos[$COL['Name']];
} elseif($COL['Type'] == 'Number') {
$this->col_sum[$COL['Name']] += $datos[$COL['Name']];
echo $this->FormatearNumero($datos[$COL['Name']]);
} elseif($COL['Type'] == 'auto_inc') {
echo $this->auto_increment++;
}
} else {
foreach($COL['Name'] as $f_name => $f_parameters) {
foreach($f_parameters as $col_name) {
$parameters[] = $datos[$col_name];
}
call_user_func_array($f_name, $parameters);
}
}
echo "</td>\n";
}
echo " </tr>\n";
}
echo " </tbody>\n";
}
public function Head($cont) {
echo " <thead>\n <tr>\n";
foreach ($cont as $tmp) {
echo " <th>$tmp</th>\n";
}
echo " </tr>\n </thead>\n";
}
public function caption($caption) {
echo " <caption>$caption</caption>\n";
}
public function Col($col) { //formato de variable array( propiedad => array( valores))
foreach($col as $clave => $valor) {
$n = 0;
foreach($valor as $tmp) {
$fila_col[$n++] .= " $clave=\"$tmp\"";
}
}
for($i = 0; $i<count($fila_col); $i++) {
echo " <col$fila_col[$i]>\n";
}
}
function FinTabla() {
echo "</table>\n";
}
private function FormatearNumero($numero) {
return number_format($numero, 2, '.', ',');
}
}
class MySQL {
private $conexion;
private $consulta;
private $error_mysql;
function __construct() {
$this->conexion = mysql_pconnect('localhost', 'root', '7135052367' );
if(!$this->conexion) {
$this->error_mysql = 'Error en la conexion';
}
mysql_select_db( 'administracion', $this->conexion) or die ('No se pudo seleccionar la base de datos');
}
function Query($Query) {
$this->consulta = mysql_query($Query, $this->conexion) or die (mysql_error());
if(!$this->consulta) {
exit();
}
}
function fecth_array() {
return mysql_fetch_array($this->consulta);
}
function fetch_assoc() {
return mysql_fetch_assoc($this->consulta);
}
function num_row() {
return mysql_num_rows($this->consulta);
}
function ultimo_id() {
return mysql_insert_id();
}
}
?>