I am trying to show in the report the result of a INNER JOIN
of 3 tables, I save the 3 values in a array
and I make a foreach
to go through all the records, but the following error appears:
Warning: Illegal string offset 'Fleet'
Warning: Illegal string offset 'FullName'
Warning: Illegal string offset 'Description'
My foreach
looks like this:
<?php foreach ($acessos as $acesso) : ?>
<tr>
<td><?php echo $acesso['Frota']; ?></td>
<td><?php echo $acesso['NomeCompleto']; ?></td>
<td><?php echo $acesso['Descricao']; ?></td>
<td class="actions text-right">
<a href="Editar.php?Codigo=<?php echo $acesso['Codigo']; ?>" class="btn btn-sm btn-warning"><i class="fa fa-pencil"></i> Inserir Entrada</a>
</td>
</tr>
This is code that queries the database:
function INNERJOIN (){
$database = open_database();
$found = null;
$sql = "SELECT tblacesso.Codigo, tblfrota.Frota, tblpessoa.NomeCompleto, tbldestino.Descricao FROM tblacesso INNER JOIN tblfrota ON(tblacesso.FrotaID = tblfrota.Codigo) INNER JOIN tblpessoa ON(tblacesso.MotoristaID = tblpessoa.Codigo) INNER JOIN tbldestino ON(tblacesso.DestinoID = tbldestino.Codigo)";
$result = $database->query($sql);
if ($result->num_rows > 0) {
$found = $result->fetch_assoc();
}
close_database($database);
return $found;
}
I used var_dump($acessos);
to check the data type of my variable and the following result appeared:
array (size=3)
'Frota' => string '9999' (length=4)
'NomeCompleto' => string 'Jean C. Galhardi' (length=16)
'Descricao' => string 'Palmares' (length=8)//////