Reputation: 47
I want to print items from table items by the Id_item found in the table favorites_items. I'm using the Codeigniter framework.
the error:
Not unique table/alias: 'favorites_items'
SELECT favorites_items., items. FROM favorites_items JOIN favorites_items ON id_item = items.id_ad
Code:
$this->db->select('favorites_items.*,items.*');
$this->db->from('favorites_items');
$this->db->join('favorites_items', 'id_item = items.id_ad');
$query = $this->db->get();
return $query->result_array();
Upvotes: 1
Views: 49
Reputation: 7997
you don't join the table items, you join the table favorites_items to the table favorites_items
the correct way would be like:
$this->db->select('favorites_items.*,items.*');
$this->db->from('favorites_items');
$this->db->join('items', 'favorites_items.id_item = items.id_ad');
$query = $this->db->get();
return $query->result_array();
Upvotes: 1