Welcome Guest, Not a member yet? Register   Sign In
Lost in the middle of mysql and objects
#3

[eluser]andriu[/eluser]
Hi Jedd

I solved it using a for loop, but it would be great If you know a better way of doing by Joining tables.

Tables:
proforma(containing invoices)
id client_name notes


proforma_products
id proforma_id qty price


proforma_discounts
id product_id amount type



The proforma has products, and products can have discounts.

The code I use now:

Code:
// Get the Proforma
$query = $this->db->get_where('proforma', array('id' => $id));

$row = $query->row();
$query = $this->db->get_where('proforma_products', array('proforma_id' => $id));

// Add products to proforma        
$row->products = $query->result();
        
foreach($row->products as $key => $value){
     $query = $this->db->get_where('proforma_discounts', array('product_id' => $value->id));
     $row->products[$key]->discounts = $query->result();
        }

return $row

This way I can access the discount for products by:
$proforma->products->discount

But as I said, If you can think of more effective way of doing this, I would be grateful.

Hopefully I explained it better this time.

Thanks


Messages In This Thread
Lost in the middle of mysql and objects - by El Forum - 10-25-2009, 09:30 AM
Lost in the middle of mysql and objects - by El Forum - 10-25-2009, 11:22 AM
Lost in the middle of mysql and objects - by El Forum - 10-25-2009, 03:52 PM
Lost in the middle of mysql and objects - by El Forum - 10-25-2009, 05:11 PM



Theme © iAndrew 2016 - Forum software by © MyBB