Hii Leute,
Was geht?
Ich versuche mich gerade an einem kleinen Programm und ich will das möglichst Objektorientiert durchziehen. Zur Übung.
Also es geht um folgedens:
Ich will ein Script schreiben, mit welchem man beliebig viele Tabellen Zellen erstellen kann und diese (jede einzelne) speziell mit Werten füllen kann.
Der erste Teil ist mir schon gelungen.
Also mit dem folgenden Code kann ich eine beliebig lange Head Zeile einfügen und beliebig viele normale Spalten und Zeilen.
Nur haben alle Head Zellen den gleichen Wert genau so wie die normalen Zellen.
ALso ich kann nicht jede einzelne Zelle speziell füllen.
Hier mal der bisherige Code:
PHP-Code:
class table {
public $set_head;
public $set_row_head;
public $set_space;
public $set_row_space;
public $table_all_struct;
public $table_all_over_struct;
public $color;
public $content_head;
public $content_space;
public $numbers_head;
public $numbers_space;
public function set_head($content_head){
$this->content_head = $content_head;
$this->set_head = "<th>\n";
$this->set_head .= $this->content_head."\n";
$this->set_head .= "</th>\n";
return $this->set_head;
}
public function set_row_head($numbers_head){
$this->numbers_head = $numbers_head;
$this->set_row_head = "<tr>\n";
$i_head_func = 1;
while($i_head_func <= $this->numbers_head){
$this->set_row_head .= $this->set_head($this->content_head);
$i_head_func++;
}
$this->set_row_head .= "</tr>\n";
return $this->set_row_head;
}
public function set_space($content_space){
$this->content_space = $content_space;
$this->set_space = "<td>\n";
$this->set_space .= $this->content_space."\n";
$this->set_space .= "</td>\n";
return $this->set_space;
}
public function set_row_space($numbers_space){
$this->numbers_space = $numbers_space;
$this->set_row_space = "<tr>\n";
$i_space_func = 1;
while($i_space_func <= $this->numbers_space){
$this->set_row_space .= $this->set_space($this->content_space);
$i_space_func++;
}
$this->set_row_space .= "</tr>\n";
return $this->set_row_space;
}
public function set_table_argument($color, $numbers_head, $numbers_space, $numbers_space_deep){
$this->color = $color;
$this->table_all_struct = "<table bgcolor='$this->color' border='1'>\n";
$this->table_all_struct .= $this->set_row_head($numbers_head);
$i_space = 1;
while($i_space <= $numbers_space_deep){
$this->table_all_struct .= $this->set_row_space($numbers_space);
$i_space++;
}
$this->table_all_struct .= "</table>\n";
return $this->table_all_struct;
}
}
$tabelle = new table();
$tabelle->set_head("Zahl");
$tabelle->set_space("210");
$tabelle->set_table_argument("#00FF00", 10, 10, 10);
echo $tabelle->table_all_struct;
?>
Ich könnte jetzt natürlich space1, space2, space 3 usw... erstellen aber ich finde das doof.
Gibt es eine gute kurze Möglichkeit, wie ich jede einzelne Zelle mit einem beliebigen Wert füllen kann?
Ich hoffe auf ein paar gute Ideen und Lösungs Vorschläge.
Wie sinnvoll das Mini Projekt ist sei mal dahingestellt.
MfG
Michael