Skip to content

Instantly share code, notes, and snippets.

@estefanionsantos
Last active September 15, 2021 20:22
Show Gist options
  • Save estefanionsantos/837da24e62d47f2bfd94f11bf66167f4 to your computer and use it in GitHub Desktop.
Save estefanionsantos/837da24e62d47f2bfd94f11bf66167f4 to your computer and use it in GitHub Desktop.
table.example02
<?php
$data = include 'dataArr.php';
$alignLeft = array('align'=>'left');
$table = new Rubricate\Table\ContainerTable();
$body = new Rubricate\Table\BodyTable();
foreach ($data as $key => $row)
{
if($key !== 0) {
$ln = new Rubricate\Table\RowTable();
$ln->addData('&nbsp;', array('colspan'=>2));
$body->addChild($ln);
}
$ln = new Rubricate\Table\RowTable();
$ln->addHead('Id', $alignLeft);
$ln->addData($row['id']);
$body->addChild($ln);
$ln = new Rubricate\Table\RowTable();
$ln->addHead('Name', $alignLeft);
$ln->addData($row['name']);
$body->addChild($ln);
$ln = new Rubricate\Table\RowTable();
$ln->addHead('Occupation', $alignLeft);
$ln->addData($row['occupation']);
$body->addChild($ln);
$ln = new Rubricate\Table\RowTable();
$ln->addHead('User', $alignLeft);
$ln->addData($row['user']);
$body->addChild($ln);
$ln = new Rubricate\Table\RowTable();
$ln->addHead('Message', $alignLeft);
$ln->addData($row['nota']);
$body->addChild($ln);
}
$table->setAttribute('border', '1');
$table->addChild($body);
echo $table->getElement();
/*
<table border="1">
<tbody>
<tr>
<th align="left">Id</th>
<td>1</td>
</tr>
<tr>
<th align="left">Name</th>
<td>John</td>
</tr>
<tr>
<th align="left">Occupation</th>
<td>Engineer</td>
</tr>
<tr>
<th align="left">User</th>
<td>@john</td>
</tr>
<tr>
<th align="left">Message</th>
<td>Lorem ipsum dolor sit amet</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<th align="left">Id</th>
<td>2</td>
</tr>
<tr>
<th align="left">Name</th>
<td>Mary</td>
</tr>
<tr>
<th align="left">Occupation</th>
<td>Doctor</td>
</tr>
<tr>
<th align="left">User</th>
<td>@mary</td>
</tr>
<tr>
<th align="left">Message</th>
<td>Curabitur a dui et nunc auctor</td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<th align="left">Id</th>
<td>3</td>
</tr>
<tr>
<th align="left">Name</th>
<td>Joseph</td>
</tr>
<tr>
<th align="left">Occupation</th>
<td>Dentist</td>
</tr>
<tr>
<th align="left">User</th>
<td>@joseph</td>
</tr>
<tr>
<th align="left">Message</th>
<td>Nunc tincidunt nisi posuere</td>
</tr>
</tbody>
</table>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment