tabel-class
Code (php)
Class:
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
class Tabel{
private $id;
public $aantal_rows = 0;
public $aantal_cols = 1;
public $aantal_cels = 0;
public $heading = array();
public $rows = array();
public function __construct($id){
$this->id = $id;
}
public function setHead($cells){
$cells = func_get_args();
if(is_array($cells)){
$this->heading = $cells;
$aantal = count($cells);
if($aantal > $this->aantal_cols){
$this->aantal_cols = $aantal;
}
}else{
$this->heading = array($cells);
}
$this->aantal_cels = $this->aantal_rows*$this->aantal_cols;
}
public function addRow($cells){
$cells = func_get_args();
if(is_array($cells)){
$aantal = count($cells);
if($aantal > $this->aantal_cols){
$this->aantal_cols = $aantal;
}
$this->rows[] = $cells;
}else{
$this->rows[] = array($cells);
}
$this->aantal_rows++;
$this->aantal_cels = $this->aantal_rows*$this->aantal_cols;
}
public function display(){
$return = '';
if(!empty($this->aantal_rows)){
$return .= "<table id=\"".$this->id."\" border=\"1\" class=\"table\">\n\n";
if(!empty($this->heading)){
$return .= "\t<tr>\n";
for($i=0;$i<$this->aantal_cols;$i++){
if(isset($this->heading[$i]) AND $this->heading[$i] != null AND $this->heading[$i] != ''){
$return .= "\t\t<th>".$this->heading[$i]."</th>\n";
}else{
$return .= "\t\t<th> </th>";
}
}
$return .= "\n\t</tr>\n\n";
}
for($a=0;$a<$this->aantal_rows;$a++){
$return .= "\t<tr>\n";
for($b=0;$b<$this->aantal_cols;$b++){
if(isset($this->rows[$a][$b]) AND $this->rows[$a][$b] != null AND $this->rows[$a][$b] != ''){
$return .= "\t\t<td>".$this->rows[$a][$b]."</td>\n";
}else{
$return .= "\t\t<td> </td>\n";
}
}
$return .= "\t</tr>\n\n";
}
$return .= '</table>';
}else{
$return .= 'Geen geldig aantal rijen';
}
return $return;
}
}
?>
class Tabel{
private $id;
public $aantal_rows = 0;
public $aantal_cols = 1;
public $aantal_cels = 0;
public $heading = array();
public $rows = array();
public function __construct($id){
$this->id = $id;
}
public function setHead($cells){
$cells = func_get_args();
if(is_array($cells)){
$this->heading = $cells;
$aantal = count($cells);
if($aantal > $this->aantal_cols){
$this->aantal_cols = $aantal;
}
}else{
$this->heading = array($cells);
}
$this->aantal_cels = $this->aantal_rows*$this->aantal_cols;
}
public function addRow($cells){
$cells = func_get_args();
if(is_array($cells)){
$aantal = count($cells);
if($aantal > $this->aantal_cols){
$this->aantal_cols = $aantal;
}
$this->rows[] = $cells;
}else{
$this->rows[] = array($cells);
}
$this->aantal_rows++;
$this->aantal_cels = $this->aantal_rows*$this->aantal_cols;
}
public function display(){
$return = '';
if(!empty($this->aantal_rows)){
$return .= "<table id=\"".$this->id."\" border=\"1\" class=\"table\">\n\n";
if(!empty($this->heading)){
$return .= "\t<tr>\n";
for($i=0;$i<$this->aantal_cols;$i++){
if(isset($this->heading[$i]) AND $this->heading[$i] != null AND $this->heading[$i] != ''){
$return .= "\t\t<th>".$this->heading[$i]."</th>\n";
}else{
$return .= "\t\t<th> </th>";
}
}
$return .= "\n\t</tr>\n\n";
}
for($a=0;$a<$this->aantal_rows;$a++){
$return .= "\t<tr>\n";
for($b=0;$b<$this->aantal_cols;$b++){
if(isset($this->rows[$a][$b]) AND $this->rows[$a][$b] != null AND $this->rows[$a][$b] != ''){
$return .= "\t\t<td>".$this->rows[$a][$b]."</td>\n";
}else{
$return .= "\t\t<td> </td>\n";
}
}
$return .= "\t</tr>\n\n";
}
$return .= '</table>';
}else{
$return .= 'Geen geldig aantal rijen';
}
return $return;
}
}
?>