Welcome Guest, Not a member yet? Register   Sign In
Need to simplify complicated db query
#2

[eluser]davidbehler[/eluser]
What exactly is your problem?
Products without images don't appear in your result?

Try using using left outer join:
Code:
$this->db->select('*');
$this->db->from(self::TABLE_PRODUCTS);
$this->db->join(self::TABLE_IMAGES, self::TABLE_IMAGES . '.product_id = ' . self::TABLE_PRODUCTS . '.product_id', 'left outer');
$this->db->join(self::TABLE_SORT, self::TABLE_SORT . '.image_id = ' . self::TABLE_IMAGES . '.id', 'left outer');
$this->db->where(self::TABLE_PRODUCTS . '.owner_id', $id);
$query = $this->db->get();

if ($query->num_rows() > 0) return $query->result_array();
return array();


Messages In This Thread
Need to simplify complicated db query - by El Forum - 09-22-2009, 06:38 AM
Need to simplify complicated db query - by El Forum - 09-22-2009, 06:41 AM
Need to simplify complicated db query - by El Forum - 09-22-2009, 07:04 AM



Theme © iAndrew 2016 - Forum software by © MyBB