Good morning, people. I'm starting in PHP and did this function below with the purpose of returning the data from two tables of my database in a table, I just can not make it work at all. Can someone help me?
MODEL:
public static function listar(){
$sql = "SELECT p.id, p.canhoto, m.nome, p.id_motorista FROM canhotos_saida p INNER JOIN motoristas m ON p.id_motorista = m.id";
$conexao = new Conexao();
$result = $conexao->consultar($sql);
$lista = new ArrayObject();
while ( list($id, $canhoto,$motorNome, $motorId) = mysqli_fetch_row( $result ) ){
$driver = new Motoristas($motorNome, $motorId);
$cs = new CanhotosSaida($id, $canhoto, $driver);
$lista->append($cs);
}
return $lista;
}
Table code:
<?php
include_once './model/clsCanhotosSaida.php';
$lista = CanhotosSaida::listar();
foreach ($lista as $nota) {
echo '<tr>';
echo ' <td>' .$nota->id. '</td> ';
echo ' <td>' .$nota->canhoto. '</td> ';
echo ' <td>' .$nota->motorista->nome. '</td> ';
echo '</tr>';
}
?>
With this code there, I get the following error:
Notice: Trying to get property of non-object in C:\xampp\htdocs\teste\notas.php on line 39
Line 39 is exactly in this snippet of table code:
echo ' <td>' .$nota->motorista->nome. '</td> ';
Detail: The note-> id and the left-hander are appearing on the table, only the name of the driver that does not ...