5
I’m trying to show in the report the result of a INNER JOIN
3 tables, save the 3 values in a array
and make a foreach
to go through all the records, but the following error appears:
Warning: Illegal string offset 'Fleet'
Warning: Illegal string offset 'Full name'
Warning: Illegal string offset 'Description'
Man foreach
is 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 makes the query in 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 a 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)//////
Thanks for the answer... I’m beginner in PHP, help me to schematize, you put the spread code to explain and I ended up getting lost, how will the code?
– user31040
Need because it can have more than one record to appear on the screen.
– user31040
I edited my question with the code that makes JOIN. I use foreach to list the results.
– user31040
The
fetch_assoc
will always return a single line, only using loop or thefetch_all
will return all, I will edit the answer.– Inkeliz
It worked... thanks for the availability.
– user31040