Welcome Guest, Not a member yet? Register   Sign In
Pagination errors...a lot
#1

[eluser]feri_soft[/eluser]
Today i hoped i can get my app running and this pagination class killed me ....

Here is the part of the controller:
Code:
$cat_info = $this->products->getCatInfo($this->uri->segment(2)); // Cat info based on the cat url_name value
        if($cat_info){
        $this->load->library('pagination');
        $config['per_page'] = '1';
        $query = $this->cats->getCurProducts($cat_info['id'], $config['per_page'], $this->uri->segment(3));
        $data['subcats'] = $this->cats->getSubCats($cat_info['id']);
        if($query){
        $config['base_url'] = base_url(). 'category/' . $this->uri->segment(2) . '/';
        $config['total_rows'] = $this->cats->countProducts($cat_info['id']);    
        $this->pagination->initialize($config);

The model:
Code:
function getCurProducts($catID, $limit, $offset){
        $this->db->select('products.title, products.short, products.price, products.category, products.id, cats.url_name, cats.name, cats.id, images.thumb, images.image, images.id');
        $this->db->from('products');
        $this->db->where('category', $catID);
        $this->db->join('images', 'images.product_id = products.id');
        $this->db->join('cats', 'cats.id = products.category');
        $this->db->limit($limit, $offset);
        $query = $this->db->get();
        
        if($query->num_rows() > 0){
            
            return $query->result_array();
        }else{
            return false;
        }    
    }
and the view:
Code:
<?php if($subcats != 0):foreach ($subcats as $subcat):?>
<a href="&lt;?=base_url().'category/'.$subcat['url_name']?&gt;">&lt;?=$subcat['name']?&gt;</a>
&lt;?php endforeach;endif;?&gt;
&lt;?php foreach($products as $p):?&gt;
<div id="product_&lt;?=$p['id']?&gt;" class="product_container">
<div id="img"></div>sdf
</div>
&lt;?php endforeach;?&gt;
<br />
&lt;?=$pagination?&gt;

And now i get:
<div id="product_5" class="product_container">
<div id="img"></div>sdf on the first and
<div id="product_" class="product_container">
<div id="img"></div>sdf on the second page

With different code like left joins and changing the query syntax a bit i came up with results like same ids on all pages or first page working second page with no results and so on. Please give me the correct query for what i am trying to do. On pagination i want not only to show the products but images and cats names so i need to join them. Without the join stuff the query is perfect and all is fine. When i attempt join in combination with pagination all screws up. PLease help!
#2

[eluser]feri_soft[/eluser]
NO one have ideas? It seems like a common thing with join and pagination as there were other posts on this one but i couldnt find the solution?




Theme © iAndrew 2016 - Forum software by © MyBB