Welcome Guest, Not a member yet? Register   Sign In
Pagination problem
#1

[eluser]Unknown[/eluser]
hi!.This is pagination error:
//this is controller
function cat($id){
//use this for the category page
$id = (int) $this->uri->segment(3);
$cat =$this->MCategories->getCategory($id);
if (!count($cat)){
redirect('kienvang/index','refresh');
}
$data['title'] = "Kien Vang | ". $cat['name'];

if ($cat['parentid']<1){
//show other categories
$data['listing'] = $this->MCategories-> getSubCategories($id);
$data['level'] = 1;
}else{
//show classifieds
$this->load->library('pagination');
$config['base_url'] = site_url('kienvang/cat');
$config['total_rows'] = $this->MClassifieds->getClassifiedsByCategory_count($id);
$config['per_page'] = 2;
$config['full_tag_open'] = '<p>';
$config['full_tag_close'] = '</p>';
//$config['uri_segment'] = 3;
$this->pagination->initialize($config);
$data['listing'] = $this->MClassifieds-> getClassifiedsByCategory($config['per_page'],(int) $this->uri->segment(4),$id);
$data['level'] = 2;
}
$data['category'] = $cat;
$data['main'] ='category';
$data['menulist'] =$this->MCategories->getCategoriesMenu();
$this->load->vars($data);
$this->load-> view('template');
}


//model

function getCategory($id){
$data = array();
$options = array('id' => $id);
$Q = $this-> db-> getwhere('categories',$options,1);
if ($Q-> num_rows() > 0){
$data = $Q-> row_array();
}
function getClassifiedsByCategory_count($catid){
$this-> db-> select('id,title,region,created');
$this-> db-> where('category_id', $catid);
$this-> db-> where('status', 'active');
$this-> db-> orderby('id','asc');
return $this->db->count_all_results('classifieds');
}

function getClassifiedsByCategory($limit,$offset,$catid){
$data = array();
$this-> db-> select('id,title,region,created');
$this-> db-> where('category_id', $catid);
$this-> db-> where('status', 'active');
$this-> db-> orderby('id','asc');
$Q = $this-> db->get('classifieds',$limit,$offset);
if ($Q->num_rows()>0){
foreach ($Q->result_array() as $row){
$data[] =$row;
}
}
$Q->free_result();
return $data;
}


///view

&lt;?php
echo "<h2 class='home'>".$category['name']."</h2>";
foreach($listing as $key=>$list){
echo "<div class='post'>";
echo "<h3 class='title'>";
switch($level){
case "1":
echo anchor('kienvang/cat/'.$list['id'],$list['name']);
echo "</h3>";
break;
case "2":
echo anchor('kienvang/classified/'.$list['id'],$list['title']);
echo "</h3>";
echo "<p class='byline'>".$list['created']." | ".$list['region']."</p>";
break;
}
echo "</div>";
}

?&gt;
&lt;?php echo pagination_links(); ?&gt;

error :
from page 2 or 3 ... is disabled.
I wish the you to help.
thank...
#2

[eluser]Zeeshan Rasool[/eluser]
well this might help you,

Code:
[color=blue]TO SHOW THE COMBO, SO THAT WE CAN CHANGE PER PAGE LISTINGS[/color]

echo form_open('admin/action',$att);
echo "Result  ". $first ." - ".$last ."  of  ".$total."&nbsp;&nbsp;";
$options = array(
            '9'      => '9',
            '18'      => '18',
            '27'      => '27',
            '36'      => '36',
            '45'      => '45',
            );
    
$value = 1;
$js = 'onchange="[removed]ShowItem('.$value.')"';
echo form_dropdown('no_r', $options,$max_record,$js);
echo form_close();

SHOW ITEM JAVASCRIPT FUNCTION

function ShowItem(value)
{
    document.frmRecordsPerPage.submit();
}


IN BOTTOM OF THE VIEW USING PAGINATION LIBRARY WE PRINT THE BUTTONS

$config['next_link'] = '<img src="'.base_url().'resources/images/next_button.jpg" alt="" title="" border="0" />';//'Next' Button;
$config['prev_link'] = '<img src="'.base_url().'resources/images/prev_button.jpg" alt="" title="" border="0" />';//'Previous' Button;
$this->pagination->initialize($config);
echo $this->pagination->create_links();


THIS IS CONTROLLER

        $result_p_page = 20;
        if($order=='')
            $order_by=0;
        else
        $order_by=$order;
        if($this->input->post('no_r')!='')
        {
            $result_p_page=$this->input->post('no_r');
        }
        elseif($this->uri->segment(3)!='')
        {
            if($this->uri->segment(3)=='')
            {
                $result_p_page = 20;
            }
            else
            {
                $result_p_page=$this->uri->segment(3);
            }
        }
        if($num_page!=0&&$value!=0)
        {
            $data['num']=$num_page;
            $data['value']=$value;
        }
        elseif($this->input->post('no_r')!=0)
        {
            $data['num']=0;
            $data['value']=$this->input->post('no_r');
        }
        else
        {
            $data['num']=0;
            $data['value']=$result_p_page;
        }  
        
  
        $config['base_url'] = base_url().'/..your address.../'.$result_p_page;
        $config['total_rows'] = $query;
        
        if($num_page==''&& $value=='')
        {
            $config['per_page'] = $result_p_page;
        }
        else
        {
            $config['per_page']=$value;
        }
        $this->pagination->initialize($config);
        
        /// YOU QUERY HERE
    
        $i=0;
        foreach($data['listing_data'] as $item)
        {
            $i++;
        }
        if($num_page=='')
        {
            $start=((sizeof($data['listing_data']))!=0?1:0);
            $data['first']=$start; $data['last']=$i;
        }
        else
        {
            $data['first']=1+$num_page;$data['last']=$num_page+$i;
        }
        $data['max_record']=$result_p_page;
    
        $data['total_rec']=$query;

/// HERE LOAD YOUR VIEW

Cheers....
#3

[eluser]Unknown[/eluser]
I do not think out,wish everybody help !




Theme © iAndrew 2016 - Forum software by © MyBB