Skip to content

Instantly share code, notes, and snippets.

@ruliarmando
Created May 6, 2014 14:54
Show Gist options
  • Save ruliarmando/ebeda58dfab393e8a8d3 to your computer and use it in GitHub Desktop.
Save ruliarmando/ebeda58dfab393e8a8d3 to your computer and use it in GitHub Desktop.
kelas Table
<?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