[eluser]clintonbeattie[/eluser]
Hi,
I am working through the Wrox Codeigniter book and keep getting this error when searching(I'm on page 126)...
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: results
Filename: views/search.php
Line Number: 5
This is my search.php file contents...
Code:
<div id='pleft'>
<h2>Search Results</h2>
<?php
if (count($results)) {
foreach ($results as $key => $list){
echo "<img src='".$list[' border='0' align='left' />\n";
echo "<h4>";
echo anchor('welcome/product/'.$list['id'],$list['name']);
echo "</h4>\n";
echo"<p>".$list['shortdesc']."</p><br style='clear:both'/>";
}
}else{
echo "<p>Sorry, no records were found to match your search term.</p>";
}
?>
</div>
All others files are as written in the book and have been double checked with the downloaded files.
Can anyone shed any light on this?
Thanks,
C
PS Here are my model view code and controller code...
Code:
function search($term){
$data = array();
$this->db->select('id,name,shortdesc,thumbnail');
$this->db->like('name',$term);
$this->db->orlike('shortdesc',$term);
$this->db->orlike('longdesc',$term);
$this->db->orderby('name','asc');
$this->db->where('status','active');
$this->db->limit(50);
$Q = $this->db->get('products');
if ($Q->num_rows() > 0){
foreach ($Q->result_array() as $row){
$data[] = $row;
}
}
$Q->free_result();
return $data;
}
Code:
function search() {
if ($this->input->post('term')) {
$search['results'] = $this->MProducts->search($this->input->post('term'));
} else {
redirect('welcome/index', refresh);
}
$data['main'] = 'search';
$data['title'] = "Claudia's Kids | Search Results";
$data['navlist'] = $this->MCats->getCategoriesNav();
$this->load->vars($data);
$this->load->view('template', $data);
}