tabel-class

Gesponsorde koppelingen

PHP script bestanden

  1. tabel-class

« Lees de omschrijving en reacties

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
<?php
//voorbeeld
    require("class.tabel.php");
    
    $tabel = new Tabel('test');
    
    $tabel->setHead('Col 1','Col 2','Col 3');
    $tabel->addRow('Rij 1, Col 1','Rij 1, Col 2');
    $tabel->addRow('Rij 2, Col 1','','Rij 2, Col 3');
    
    echo $tabel->display();
?>


Class:
Code (php)
PHP script in nieuw venster Selecteer het PHP script
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
<?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>&nbsp;</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>&nbsp;</td>\n";
                                }
                            }

                        $return .= "\t</tr>\n\n";
                    }

                $return .= '</table>';
            }
else{
                $return .= 'Geen geldig aantal rijen';
            }

            
            return $return;
        }
    }

?>

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.