0
我有announcements
表,其中我存儲了announcements.catid
(類別ID)。MySQL在CodeIgniter中在同一個表中加入兩個不同的列兩次
分類表categories
用於嵌套使用categories.pid
。
我想要做的是獲取在多維數組內嵌套的類別。
這裏是我怎麼想它是在圖像內突出部分:
這裏是代碼:
public function get_mixed($limit = NULL, $offset = NULL)
{
$this->db
->select('
announcements.id,
announcements.catid,
announcements.uid,
categories.title AS section,
categories.title AS category,
announcements.title,
announcements.text,
announcements.views,
announcements.created,
announcements.modified,
announcements.pubdate
')
->join('categories', 'announcements.catid = categories.id', 'left')
->join('categories as section', 'categories.pid = section.id', 'left')
->order_by('created DESC, '.$this->_order_by);
return $this->db->get($this->_table_name, $limit, $offset)->result();
}
我第一次嘗試通過創建section
別名,但它得到了同樣的結果。
也許有更好的方法?
正是我想要的,我忘了在SELECT中引用別名。謝謝 – aspirinemaga