I am trying to populate an array into a HTML table, but I keep getting Notice: Undefined offset
What am I doing wrong?
<?php
class Invoices{
public $database;
public $exec;
public function __construct() {
$this->database = new Dbase();
}
public function show()
{
$query="SELECT * FROM invoices;";
$this->exec=$this->database->fetch($this->database->run($query));
echo '<table class="table table-striped table-bordered"><thead>
<tr>
<th>ID</th>
<th>Customer ID</th>
<th>Products</th>
<th>Total</th>
<th>Status</th>
<th></th>
</tr>
</thead>';
for ($i=0; $i<count($this->exec, 0); $i++)
{
echo '<tr>';
for ($j=0; $j<5; $j++)
{
echo '<td>'.$this->exec[$i][$j].'</td>';
}
echo '</tr>';
}
echo '</table>';
}
}
Below are the results of vardump on the $exec array.
foreach
loop instead would simplify things. – Don't Panic 3 hours ago