Welcome Guest, Not a member yet? Register   Sign In
Codeigniter Unable to join the table properly
#3

(This post was last modified: 02-23-2017, 08:28 PM by AzrielOmega.)

First, if one product belong only for one category, you don't need t_cp_link table. Just add CategoryID column to Product table
You don't need CategoryID in Product Pack table either, if the ProductID is unique already.

Now you will have 3 table: Category, Product and ProductPack. the Query should be like this:

$this -> db -> select('Category.CategoryID, CategoryName, Product.ProductID, Product.ProductName, Pack.Dosage, Pack.Unit_price, Pack.Selling_price, Pack.Stock');
$this -> db -> from('ProductPack as Pack');
$this->db->join('Product', 'Product.ProductID = Pack.ProductID', 'left');
$this->db->join('Category', 'Category.CategoryID = Product.CategoryID', 'left'); 
$this->db->order_by("Product.ProductID", "ASC");  
$query = $this->db->get();
if ($query -> num_rows() > 0) {
    return $query -> result_array(); // or result();
} else {
    return false;
}
Reply


Messages In This Thread
RE: Codeigniter Unable to join the table properly - by AzrielOmega - 02-23-2017, 08:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB