2015-06-22 90 views
-1
 //model 
public function getAllPurchaseItems($purchase_id) 
{ 
    $this->db->select('purchase_items.purchase_id, 
    purchase_items.transfer_id, purchase_items.product_id, 
    purchase_items.product_code, purchase_items.product_name, 
    purchase_items.option_id, purchase_items.net_unit_cost, 
    purchase_items.quantity, purchase_items.warehouse_id, 
    purchase_items.item_tax, purchase_items.tax, purchase_items.discount, 
    purchase_items.item_discount, purchase_items.expiry, 
    purchase_items.subtotal, purchase_items.quantity_balance, 
    purchase_items.date, purchase_items.status, categories.name'); 
    $this->db->from('purchase_items'); 
    $this->db->join(products, 'products.id = purchase_items.product_id'); 
    $this->db->join(categories, 'categories.id = products.category_id'); 
    $this->db->order_by('purchase_items.id', 'asc'); 
    $q = $this->db->where(array('purchase_items.purchase_id' => 
     $purchase_id)); 

    if ($q->num_rows() > 0) { 
     foreach (($q->result()) as $row) { 
      $data[] = $row; 
     } 

     return $data; 
    } 
    return FALSE; 
} 

// controller 
$this->data['rows'] = $this->purchases_model->getAllPurchaseItems($purchase_id); 
+0

正確地格式化代碼1 – Bugfixer

+0

只是代碼?你錯過了'」「'你的連接查詢。使用「產品」和「類別」。加入查詢不起作用或者你犯了錯誤? –

回答

0

模型篩選

$this->db->select('purchase_items.purchase_id, purchase_items.transfer_id, purchase_items.product_id, purchase_items.product_code, purchase_items.product_name, purchase_items.option_id, purchase_items.net_unit_cost, purchase_items.quantity, purchase_items.warehouse_id, purchase_items.item_tax, purchase_items.tax, purchase_items.discount, purchase_items.item_discount, purchase_items.expiry, purchase_items.subtotal, purchase_items.quantity_balance, purchase_items.date, purchase_items.status, categories.name'); 
    $this->db->from('purchase_items'); 
    $this->db->join('products', 'products.id = purchase_items.product_id'); 
    $this->db->join('categories', 'categories.id = products.category_id'); 
    $this->db->where(array('purchase_items.purchase_id' => $purchase_id)); 
    $q = $this->db->order_by('purchase_items.id', 'asc'); 
    $query = $this->db->get(); 
     if($query->num_rows() != 0) 
     { 
      return $query->result_array(); 
     } 
     else 
     { 
      return false; 
     } 
+0

它不工作,因爲我寫你的更正的代碼 –

+0

謝謝你的代碼工作正常 –