Created
May 6, 2014 14:54
-
-
Save ruliarmando/ebeda58dfab393e8a8d3 to your computer and use it in GitHub Desktop.
kelas Table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Table | |
{ | |
private $result; | |
private $header; | |
private $offset; | |
public function __construct($result, $header, $offset = 1) | |
{ | |
if($result == null){ | |
die("Result tidak ada"); | |
} | |
$this->result = $result; | |
$this->header = $header; | |
$this->offset = $offset; | |
} | |
public function generate() | |
{ | |
echo '<table style="border:1px solid black;border-collapse:collapse;">'; | |
echo '<thead>'; | |
echo '<tr>'; | |
echo '<th style="border:1px solid black;">#</th>'; | |
foreach($this->header as $h){ | |
echo "<th style='border:1px solid black;'>$h</th>"; | |
} | |
echo '</tr>'; | |
echo '</thead>'; | |
echo '<tbody>'; | |
foreach($this->result as $r){ | |
$this->offset++; | |
echo '<tr>'; | |
echo "<td style='border:1px solid black;padding:5px;'>{$this->offset}</td>"; | |
foreach($this->header as $h){ | |
echo "<td style='border:1px solid black;padding:5px;'>".$r[$h]."</td>"; | |
} | |
echo '</tr>'; | |
} | |
echo '</tbody>'; | |
echo '</table>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment