Advertisement
newbie296

Fungsi Order by tidak berfungsi di codeigniter

Oct 15th, 2015
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.00 KB | None | 0 0
  1. MODEL
  2. <?php if(!defined('BASEPATH')) exit('No direct script access allowed');
  3.  
  4. class M_home extends CI_model{
  5.     private $tbl_product ='product';
  6.  
  7.     var $tableProduct   = 'product';
  8.     var $tableCategory  = 'category';
  9.     function __construct(){
  10.         parent::__construct();
  11.     }
  12.  
  13.     function listProductPerCategory($id, $limit, $start){
  14.         $this->db->select('
  15.             category.id, category.category, product.id, product.id_category,
  16.             product.name, product.picture, product.description, product.permalink, product.part_no
  17.         ');
  18.         $this->db->from('product');
  19.         $this->db->join('category', 'product.id_category = category.id');
  20.         $this->db->where('product.id_category', $id);
  21.        
  22.         $this->db->order_by('product.part_no','ASC');
  23.         $this->db->limit($limit, $start);
  24.         $query = $this->db->get();
  25.         //$query = $this->db->get_where($this->tableCategory);
  26.         return $query->result();
  27.     }
  28.  
  29.     function listProductPerCategory_num_rows($id){
  30.     $this->db->select('*');
  31.     $this->db->from('product');
  32.     $this->db->join('category', 'product.id_category = category.id');
  33.     $this->db->where('product.id_category', $id);  
  34.     $data = $this->db->get();
  35.     return $data->num_rows();
  36.     }
  37. }
  38. ?>
  39.  
  40. Controller
  41. <?php if(!defined('BASEPATH')) exit('No direct script access allowed');
  42.  
  43. class Home extends CI_Controller{
  44.     private $limitproduk=16;
  45.  
  46.     function __construct(){
  47.         parent::__construct();
  48.         $this->load->model('frontend/M_home', '', True);
  49.         $this->load->helper('url');
  50.     }
  51.     function listcategory($page=null){
  52.    
  53.         $id = $this->input->get('list');
  54.         $data['categoryHead'] = $this->M_home->listCategory();
  55.         $this->load->view('frontend/template/header', $data);
  56.         $data['productsLast'] = $this->M_home->listProductLast();
  57.         $data['productsLast2'] = $this->M_home->listProductLast2();
  58.         $data['category'] = $this->M_home->listCategory();
  59.        
  60.         $jumlah = $this->M_home->listProductPerCategory_num_rows($id);
  61.  
  62.         $config['base_url'] = base_url('categoryproduct'.'?'.http_build_query($_GET));
  63.         $config['total_rows'] = $jumlah;
  64.         $config['per_page'] = 12;
  65.         $config['first_link']       = 'First';
  66.         $config['last_link']        = 'Last';
  67.         $config['next_link']        = 'Next';
  68.         $config['prev_link']        = 'Prev';
  69.         $config['page_query_string'] = TRUE;       
  70.         $dari = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
  71.         $data['listCategory'] = $this->M_home->listProductPerCategory($id, $config['per_page'],$dari);
  72.         $this->pagination->initialize($config);
  73.         $this->load->view('frontend/category', $data);
  74.         $this->load->view('frontend/template/footer');
  75.         //end paging
  76.     }
  77. }
  78. ?>
  79. VIEW
  80. <div class="middle-main"><!--features_items-->
  81.                         <?php $this->input->get('listCategory');?>             
  82.                         <?php if(isset($listCategory)) : foreach ($listCategory as $row) :?>
  83.                         <div class="col-sm-4">
  84.                             <div class="product-image-wrapper">
  85.                                 <div class="single-products">
  86.                                         <div class="productinfo text-center">
  87.                                             <?php if(!empty($row->picture)): ?>                                    
  88.                                             <img src="<?=site_url();?>template/backend/uploads/products/<?php echo $row->picture ;?>" height="180" alt="" />
  89.                                             <?php else :?>
  90.                                             <img alt="" src="http://placehold.it/50x35">
  91.                                             <?php endif;?>                                         
  92.                                             <tr><h2><?php echo $row->category ;?></h2></tr>
  93.                                             <tr><p><?php echo substr($row->name, 0, 100) ;?></p></tr>                                          
  94.                                                 <p><?php echo $row->part_no;?></p>
  95.                                     <tr><a href="<?= site_url("view")."?productdetail=".$row->id;?>" class="btn btn-default add-to-cart"><i class="fa fa-check"></i>Details</a></tr>
  96.                                            
  97.                                    
  98.                                         </div>
  99.                                
  100.                                        
  101.                                 </div>
  102.                             </div>
  103.                         </div>
  104.                         <?php  endforeach; ?>
  105.                         <?php endif; ?>
  106.                     </div><!--features_items-->
  107.  
  108.                     <div class="pagination-area">
  109.                        
  110. <!--                                <li><a href="" class="active">1</a></li>
  111.                                 <li><a href="">2</a></li>
  112.                                 <li><a href="">3</a></li>
  113.                                 <li><a href=""><i class="fa fa-angle-double-right"></i></a></li> -->
  114.                                 <?php echo $this->pagination->create_links(); ?>
  115.  
  116.                     </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement