このエラーが発生しています:
PHP エラーが発生しました
重大度: 通知
メッセージ: 未定義の変数: 結果
ファイル名: views/body.php
ライン番号: 75
私のモデル
function get_results($search_term='default')
{
$this->db->select('*');
$this->db->from('books');
$this->db->like('title', $search_term);
$query = $this->db->get();
return $query->result_array();
}
私のコントローラー
function execute_search(){
$this->load->model('books_model');
$search_term = $this->input->post('search');
$data['results'] = $this->books_model->get_results($search_term);
$this->load->view('body', $data);
}
私の見解
<h1>Search Results</h1>
<div>
<?php
if(is_array($results)) : foreach ($results as $val) : ?>
<ul>
<li><?php echo $val['title'] ?></li>
</ul>
<?php endforeach; ?>
<?php else : ?>
<h2> No books found </h2>
<?php endif; ?>
</div>
コントローラーで変数「results」を呼び出しましたが、ビューで機能していないため、わかりません。助けてくれてありがとう。