Skip to content

Instantly share code, notes, and snippets.

@estefanionsantos
Created September 15, 2021 20:24
Show Gist options
  • Save estefanionsantos/d6e0bbb33dfb9abe7559af2812f178c0 to your computer and use it in GitHub Desktop.
Save estefanionsantos/d6e0bbb33dfb9abe7559af2812f178c0 to your computer and use it in GitHub Desktop.
table.example03
<?php
$data = include 'dataArr.php';
$table = new Rubricate\Table\ContainerTable();
$header = new Rubricate\Table\HeadRowTable();
$body = new Rubricate\Table\BodyTable();
$foot = new Rubricate\Table\FootRowTable();
$table->setAttribute('border', '1');
$header->addHead('Id');
$header->addHead('Name');
$header->addHead('Occupation');
$header->addHead('Salary');
$table->addChild($header);
$total = 0;
foreach ($data as $i => $row)
{
$ln = new Rubricate\Table\RowTable();
$ln->addData($row['id']);
$ln->addData($row['name']);
$ln->addData($row['occupation']);
$ln->addData('$ ' . $row['salary']);
$body->addChild($ln);
$total += $row['salary'];
}
$table->addChild($body);
$foot->addHead("Total", array('colspan' => 3, 'align'=>'left'));
$foot->addData('$ ' . $total);
$table->addChild($foot);
echo $table->getElement();
/*
<table border="1">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Occupation</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>John</td>
<td>Engineer</td>
<td>$ 18000</td>
</tr>
<tr>
<td>2</td>
<td>Mary</td>
<td>Doctor</td>
<td>$ 15000</td>
</tr>
<tr>
<td>3</td>
<td>Joseph</td>
<td>Dentist</td>
<td>$ 10000</td>
</tr>
</tbody>
<tfoot>
<tr>
<th colspan="3" align="left">Total</th>
<td>$ 43000</td>
</tr>
</tfoot>
</table>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment