DBGrid v.0.1
Der Grid soll einfach den Inhalt einer Tabelle anzeigen.
<?php
class DBGrid {
var $table;
var $css_table_class;
var $css_tr_class;
var $css_th_class;
var $css_td_class;
var $felder = array();
/*
Dieser Array enthält die Titel der Felder, ist für ein Feld kein Title vorhanden wird dieses Feld nicht angezeigt.
useage:
array(
'feld1' => 'beschreibung feld 1',
'feld2' => 'beschreibung feld 2',
)
*/
var $header = array();
var $html;
function genheader() {
$result = '<table class="'.$this->css_table_class.'">';
$result.= '<tr class="'.$this->css_tr_class.'">';
foreach ($this->header as $key => $value) {
$result.= '<th class="'.$this->css_th_class.'">'.$row[$key].'</th>';
}
$result.= '</tr>';
return $result;
}
function genfooter() {
$result = '</table>';
return $result;
}
function user-175() {
$out = '';
$sql = "SELECT * FROM ".$this->table."";
$result = mysql_query($sql);
while ( $row = mysql_fetch_array($result) ) {
$out .= '<tr class="'.$this->css_tr_class.'">';
foreach ($this->header as $key => $value) {
if (isset($row[$key])) {
$out .= '<td class="'.$this->css_td_class.'">'.$value.'</td>';
}
}
$out .= '</tr>';
}
$this->html = $this->genheader() . $out . $this->genfooter();
}
function show() {
echo $this->html;
}
}
/* Beispiel
mysql_connect("localhost","root",""
mysql_select_db("cdcol"
$grid = new DBGrid();
$grid->table = "cds";
$grid->header = array(
'titel' => 'Titel'
);
$grid->execute();
$grid->show();
*/
?>