[eluser]smickiedoo[/eluser]
gives the error:
Message: Undefined index: name
Filename: views/search.php
OK, this is getting to me now. All I'm trying to do is display search results on a page.
My code is as follows:
Model recipe.php
Code:
class Recipe extends Model {
function Recipe(){
parent::Model();
}
function get_recipe_data() {
$query = $this->db->query("SELECT id, user_id, name, prep_time, cook_time, directions, photo, submitted_time FROM recipes");
$data = array();
$data['recipes']=array();
foreach($query->result() as $row) {
array_push($data['recipes'],array('id' => $row->id, 'name' => $row->name, 'prep_time'=> $row->prep_time));
}
return $data;
}
}
Controller search.php
Code:
<?php
class Search extends Controller {
function Search()
{
parent::Controller();
$this->load->model('recipe');
}
function index()
{
$data['title'] = "RecipeMatcher - Serch: ";
$this->form_validation->set_rules('search', 'Search', '');
if ($this->form_validation->run() == TRUE) {
$data['recipes'] = $this->recipe->get_recipe_data();
$this->load->view('header', $data);
$this->load->view('search_bar');
$this->load->view('search', $data);
$this->load->view('footer', $data);
}
else {
$data['search_success'] = FALSE;
$this->load->view('header', $data);
$this->load->view('search_bar');
$this->load->view('search', $data);
$this->load->view('footer', $data);
}
}
}
?>
View search.php
Code:
<?php
foreach($recipes as $recipe) {
?>
<div class="recipe_box">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100" align="left" valign="top"><img src="<?=base_url()?>system/application/assets/images/recipe/noPhotoSmall.gif" /></td>
<td valign="top">
<span style="font-size:16px; color:#000000;"><b><?=$recipe['name']?></b></span><br />
</td>
</tr>
</table>
</div>
<?php
}
?>
If there is a very easy and simple way to achieve this, that's what I want. If array_push is not necessary I'd rather not have the overhead of the function.
big thanks for any help with this.