I am trying to get two values 'total number of movies' and 'details of movies' from database. For total number of movies, i am returning with php error "undefined_index:num_films". please help me.
Sakila_control
<?php
class Sakila_control extends CI_Controller
{
function display($offset=0)
{
$limit = 20;
$this->load->model('films_model');
$result = $this->films_model->search($limit,$offset);
$data['films']=$result['rows'];
$data['num_results']=$result['num_films'];
$this->load->view('films_view',$data);
}
}
Films_model
<?php
class Films_model extends CI_Model
{
function search($limit,$offset)
{
$qu = $this->
db->select('FID,title,description,category,price,length,rating,actors')
->from('film_list')
->limit($limit,$offset);
//rows comes from controller
$ret['rows']= $qu->get()->result();
return $ret;
$q = $this->db->select(`COUNT(*) as count`, FALSE)
->from('film_list');
//num_rows comes from controller
$tmp= $q->get()->result();
$ret['num_films']=$tmp[0]->count;
return $ret;
}
}
Films_view
<body>
<table>
<div>
Found <?php echo $num_results;?> Films
</div>
<thead>
<th>ID</th>
<th>Title</th>
<th>description</th>
<th>category</th>
<th>price</th>
<th>length</th>
</thead>
<tbody>
<?php
foreach($films as $film):?>
<tr>
<td><?php echo $film->FID;?> </td>
<td><?php echo $film->title;?></td>
<!-- <td><?php echo $film->description;?></td> -->
<td><?php echo $film->category;?></td>
<td><?php echo $film->price;?></td>
<td><?php echo $film->length;?></td>
<td><?php echo $film->rating;?></td>
<!-- <td><?php echo $film->actors;?></td> -->
</tr>
<?php endforeach;?>
</tbody>
</table>
</body>
</html>