视图中的分页不显示codeigniter上的最后一个条目

时间:2012-01-31 12:54:11

标签: codeigniter pagination

我有这个问题: codeigniter分页类的链接不显示最后一个条目,

e.g。如果返回的总行数为2,则它将显示在一个结果上,而指向最后一个条目的链接将显示为灰色。

这是控制器:

function productlisting () {

  $ids=$this->uri->segment(3);
  $this->load->library('pagination');
  $config['base_url'] = base_url().'index.php/listing_category/productlisting/'.$ids;
  $config['per_page'] = '1';

  $this->load->model('product_model');

  $config['total_rows'] =$this->load->model('product_model')->get_num_product();

  $this->pagination->initialize($config);
 //load the model and get results
  $pages = $this->uri->segment(3);//? $this->uri->segment(4) : 0;
                                                                                                $query['products']=$this->load->model('product_model')->get_specific_product($config['per_page'],$pages);
    $query['paginated']=$this->pagination->create_links();
       // load the view

echo $config['base_url'].'<br/>';
echo 'total rows:'. $config['total_rows']; 

$this->template->build('product_display',$query);

} 


这是我的模特

//query to get the total number of rows

function get_num_product(){

   $listingcategory = $this->uri->segment(3);
   $this->db->select('default_listings.listing_id_unique,manufacturer,imagename,item_location,thumbnail,default_listings.item_category_id,product_name,item_serial_number,item_description,size,accessories,othercharacteristics,product_age');

$this->db->where('default_listings.item_category_id',$listingcategory);
$this->db->from('default_listings');

$this->db->join('default_listings_pics', 'default_listings.listing_id_unique=default_listings_pics.listing_id_unique', 'left');

$this->db->distinct('listing_id_unique');
$this->db->group_by('default_listings.listing_id_unique');

$queried= $this->db->get();

$rowcount = $queried->num_rows();
return $rowcount;
}



// Query to get the actual entries
function get_specific_product($num, $offset){

  $listingcategory = $this->uri->segment(3);
  $this->db->select('default_listings.listing_id_unique,manufacturer,imagename,item_location,thumbnail,default_listings.item_category_id,product_name,item_serial_number,item_description,size,accessories,othercharacteristics,product_age');

  $this->db->where('default_listings.item_category_id',$listingcategory);
  $this->db->from('default_listings');
  $this->db->join('default_listings_pics', 'default_listings.listing_id_unique=default_listings_pics.listing_id_unique', 'left');
  $this->db->distinct('listing_id_unique');
  $this->db->group_by('default_listings.listing_id_unique');
  $this->db->limit($num, $offset);
  $query= $this->db->get()->result();

  return $query;

  }

,最后是我的观点

 <div id="catetogorylisitngcover">
      <h1>Products</h1>
    <?php foreach ( $products as  $productdetail):?>

      <div class="eachproducts">

      <div class="productimage">
         <?php if($productdetail->thumbnail):?>
              <img src="<?php echo base_url();?>pictures/<?php echo $productdetail->thumbnail;?>"/>
        <?php else :?>
          <img src="<?php echo base_url();?>img/noimage.png"/>
     </div>
    <div class="productcover">
     <div><span >Category Id:</span><span class="producttext"><?php  echo  $productdetail->item_category_id ;?></span></div>

  <div><span >Product Name:</span><span class="producttext"><?php  echo $productdetail->product_name;?></pan></div>  

   <div><span >Manufacturer :</span><span class="producttext"><?php  echo  $productdetail->manufacturer;?></span></div>

   <div><span >Location :</span><span class="producttext"><?php  echo  $productdetail->item_location;?></span></div>
    <div><span >Listing Id :</span><span class="producttext"><?php  echo  $productdetail->listing_id_unique;?></span></div>
 <div class="learmoreproduct"><a href="lister/specificDetails/<?php  echo intval($productdetail->listing_id_unique);?>"><img src="<?php echo base_url();?>img/prodreadmore.png"/></a></div>  

  </div>

 </div>

<?php endforeach;?>
<?php echo $this->pagination->create_links(); ?>
</div>

需要帮助!

1 个答案:

答案 0 :(得分:0)

将其用作

$this->load->library('pagination');
$config['base_url'] = your base url without offset in your case // base_url().'index.php/listing_category/productlisting/';
$config['total_rows'] = your total number of rows;
$config['per_page'] = number of rows you want to display;
$config['uri_segment'] = uri segment which will be used as offset;
$this->pagination->initialize($config);