[eluser]EdgeTube[/eluser]
Hi all,
I am attempting to integrate the pagination library with my site, except I'm having this error of invalid argument. It seems like no data is being passed to the view?
Here's my code:
Model:
Code:
<?
class Proddb extends CI_Model
{
function __construct()
{
parent::__construct();
}
public function record_count()
{
return $this->db->count_all('products');
}
public function fetch_products($limit,$start,$new_str)
{
$query = $this->db->query("SELECT * FROM products WHERE `category` = '$new_str' LIMIT $limit, $start");
if($query->num_rows()>0)
{
foreach ($query->result() as $row)
{
$datas[] = $row;
}
return $datas;
}
else
{
return FALSE;
}
}
}
?>
Controller:
Code:
$new_cat = str_replace(" "," ", $category);
$new_str = urldecode($new_cat);
$data['category'] = $new_str;
$config['base_url'] = base_url() . 'category/index';
$config['total_rows'] = $this->Proddb->record_count();
$config['per_page'] = 5;
$config['uri_segment'] = 4;
$this->pagination->initialize($config);
$page = ($this->uri->segment(4))? $this->uri->segment(4) : 0;
$data['results'] = $this->Proddb->fetch_products($config['per_page'],$page, $new_str);
$data['links'] = $this->pagination->create_links();
$this->load->view('category/view',$data);
View:
Code:
<?
foreach ($results as $row_sub):
echo "".$row_sub->title."";
endforeach;
?><?=$links?>
Not sure what I'm doing wrong with the pagination.
Here's the error:
Code:
Severity: Warning
Message: Invalid argument supplied for foreach()
Filename: category/view.php
Some advice on how to fix the issue would be appreciated. I bet there are a lot of errors, but forgive my first time trying to understand this pagination library!
Thanks!