0
I have the following error: Trying to get Property of non-object in.
Found in this code snippet.
<tr class="success">
<td> <?=$reg->getServico ?></td> ******//Erro se encontra nesta linha//************************
<td> <?=$reg->getValor ?> </td>
</tr>
I don’t know what it is, if anyone can help me, follow the code below:
class o dao service.
<?php
require_once('./until/bd.class.php');
$objBd = new bd();
$con = $objBd->conecta_mysql();
class ServicoDAO{
public function listar_servico( ){
global $con;
$servico_vo = new ServicoVO();
$query = ("SELECT * FROM servico ");
$stmt = $con->query($query);
while ($rs= $stmt->fetch_array()) {
$servico_vo->setIdServico($rs['id_servico']) ;
$servico_vo->setServico($rs['nome_servico']) ;
$servico_vo->setValor($rs['valor']);
return $rs;
}
}
}
Page that displays values
<body>
<div class="container">
<div class="page-header">
<h1>Listar Serviço</h1>
</div>
<table class="table table-striped table-bordered table-hover table-condensed ">
<thead>
<th>Produto</th>
<th>Fabricante</th>
<th>Preço</th>
</thead>
<tbody>
<?php
$CPDAO = new ServicoDAO();
$query = $CPDAO->listar_servico();
foreach($query as $reg):
?>
<tr class="success">
<td> <?=$reg->getServico ?></td> ******//Erro se encontra nesta linha//************************
<td> <?=$reg->getValor ?> </td>
</tr>
</tbody>
<?php
endforeach;
?>
</table>
</body>
Can you put the complete error? On which line is?
– Jorge B.
Cara has already been solved.... The problem already in the description is the error is found in the line described as "/Error is found in this line//".
– junio
@junio seems to be the case mark an answer as accepted. Here we do not write "solved" in the question. If you have an answer that really helped you, mark it as accepted. If you came to the solution on your own, put in the solution as an answer. So content is more organized and easier to find in the future by other people with similar problems.
– user28595
Yes sorry , I thought just write "solved" finished the post , but I marked the answer below as accepted already , not knowing that was the solution.
– junio
Sorry for the inconvenience , but I’m new to the forum. I already edited the post.
– junio