3
Model:
public function exibir_noticia()
{
$consulta = $this->db->query('SELECT * FROM Noticia_Site_Cairu');
return $consulta->result();
}
Controller
public function index()
{
$this->load->model('noticia_model');
$consulta = $this->noticia_model->exibir_noticia();
//print_r($casdatrado);
$this->load->view('v_home', $consulta);
}
When I go to show in the view:
foreach ($consulta as $exibir):{
echo '
<tr class="success">
<td>'.$exibir->titulo.'</td>
<td>'.$exibir->texto.'</td>
<td>'.$exibir->imagem.'</td>
<td>'.$exibir->link.'</td>
<td>'.$exibir->nome_link.'</td>
<td>'.$exibir->video.'</td>
<td>'.$exibir->data.'</td>
</tr>';
}endforeach;
This error appears:
PHP Error was encountered
Severity: Notice
Message: Undefined variable: query
Filename: views/v_home.php
Line Number: 88
Backtrace:
File: /var/www/html/admnoticias/application/views/v_home.php Line: 88 Function: _error_handler
File: /var/www/html/admnoticias/application/controllers/Home.php Line: 17 Function: view
File: /var/www/html/admnoticias/index.php Line: 315 Function: require_once
Thanks worked! Always have to put an array??? I thought just sending the variable was enough. Thank you very much!
– user55375
@web_charles yes always, this is common. See that in your example you passed only one variable, and if they were more like you would do? an array would no longer be practical? :)
– rray
is true! Thanks for the tip ;)
– user55375
@web_charles vc can mark one of the answers as 'accepted' (green light) it means one of them solved your problem. You can see more details on: How and why to accept an answer?.
– rray