bisa tolong betulin coding paging codeigniter?hasil dari view barangnya itu bukannya berdasarkan pagination tapi terus memanjang kebawah tanpa ada batasan.
class Cart extends CI_Controller {
function __construct()
{
parent::__construct();
$this->load->library('pagination') ;
$this->load->model('product_model');
}
function index()
{
$fb_data = $this->session->userdata('fb_data');
$data = array('fb_data' => $fb_data);
$data['products'] = $this->Cart_Model->retrieve_products(); // Retrieve an array with all products
//echo $this->db->last_query();
$data['title']='';
$data['email'] = $this->session->userdata('email');
$data['category'] = $this->Category_Model->getCategoryWhereShown();
$data['best_seller'] = $this->Product_Model->getProductBestSeller();
$data['merk_menu'] = $this->Merk_Model->getAll();
$data['category_menu'] = $this->Category_Model->getAll();
$data['subcategory_menu'] = $this->Category_Model->getAllSubCategory();
$data['hot_news'] = $this->News_Model->getNewsWhereShown();
$data['query']=$this->Product_Model->featured();//pagination
if(empty($email)){
$this->load->view('products',$data);
}else{
$this->load->view('products', $data); // Display the page
}
}
}
class Product_Model extends CI_Model{
function featured(){
$string_query = "SELECT * FROM `products` WHERE `show`=1 order by code";
$query1 = $this->db->query($string_query);
$config['total_rows'] = $query1->num_rows();
$config['per_page'] = '9';
$config['base_url'] = base_url().'cart/index';
$num = $config['per_page'];
$offset = $this->uri->segment(3);
$offset = ( ! is_numeric($offset) || $offset < 1) ? 0 : $offset;
if(empty($offset))
{
$offset=0;
}
$this->pagination->initialize($config);
$data['query'] = $this->db->query($string_query." limit $offset,$num");
return $query1->result_array();//return $query1 atau return $data['query']???
$data['base'] = $this->config->item('base_url');
return $data;
} }
view
<?php foreach($query as $row){
$image = explode(';',$row['picture']);
$img_thumb =substr($image[0],0,-4)."_thumb";
$ext=substr($image[0],-4);
$img_thumb .=$ext;
?>
<div id="wrapConPro01">
<div id="conProItem01">
<a href="<?=base_url()?>catalog/subItem/<?=$row['code']?>">
<img src="http://localhost/inibayiku/images/thumbnail/<?=$img_thumb?>" />
</a>
</div>
<div id="" align="left"><?php echo $row['name']; ?></div>
<div id="" align="left">Rp <?php echo number_format($row['price'],2,',','.'); ?></div>
<div id="conProImg01"></div>
<?php echo form_open('cart/add_cart_item'); ?>
<label>Quantity</label>
<?php echo form_input('quantity', '1', 'maxlength="2" size="2"'); ?>
<?php echo form_hidden('product_id', $row['code']); ?>
<?php echo form_submit('add', '','style="background:url('.base_url().'images/cartPro01.jpg);height:40px;width:90px;border:0px;cursor:pointer"'); ?>
<?php echo form_close(); ?>
</div>
<?php
}
?>
Jadi, saya ingin menampilkan produk yang kolom show-nya bernilai 1 pada tabel products dimana per page hanya menampilkan 9 produk. hasil dari coding di atas malah menampilkan semua produk meskipun link pagination muncul.