0
請幫助我,如何獲取類別的父母名稱。我有這樣的桌子。如何從類別ID使用codeigniter得到結果的父類名稱
table Category
+-------------+-----------------+-----------------+---------------+
| category_id | category_name | category_parent | category_slug |
+-------------+-----------------+-----------------+---------------+
| 7 | Framework CSS | 0 | |
| 9 | Bootstrap | 7 | |
| 10 | Material Design | 7 | |
+-------------+-----------------+-----------------+---------------+
table relationship
+-----------------+---------+-------------+
| relationship_id | post_id | category_id |
+-----------------+---------+-------------+
| 35 | 59 | 9 |
+-----------------+---------+-------------+
我使用codeigniter,我有一個函數來獲取帖子和類別。
public function post_detail($tableName, $where = '')
{
$post_title = $this->uri->segment(3);
$query = $this->db->query("SELECT p.*, r.*, c.* FROM tbl_relationship AS r
INNER JOIN tbl_posts AS p ON r.post_id = p.post_id
INNER JOIN tbl_category AS c ON r.category_id = c.category_id
WHERE p.post_name = '$post_title'
");
return $query->result();
}
函數結果:(7和bootstrap)。如何產生7.的父母名稱?
http://stackoverflow.com/questions/4116416/parent-child-in-same-table 7或7名 – dev
家長的名字? –
父母的名字! category_id 7的父級名稱是framework css。 – bl4ck