この形式のリレーショナル データベースがあります
Table: posts
Columns: post_id,post_title,post_content
Table: categories
Columns: category_id,category_name
Table: posts_categories
Columns: post_id,category_id
投稿には複数のカテゴリを含めることができるので、投稿とカテゴリ ID を使用して posts_categories に保存します。以下のクエリを使用してデータベースから結果を取得すると、最後のカテゴリが表示されます。すべてのカテゴリを表示することは可能ですか。それ以外の場合は別のクエリを実行する必要があります。ここに私のコード。
$this->db->select("p.*,pc.*,c.*");
$this->db->where('post_id', $id);
$this->db->from('posts AS p');
$this->db->join('posts_categories AS pc', 'pc.post_id = p.post_id', 'inner');
$this->db->join('categories AS c', 'pc.category_id = c.category_id', 'inner');
$q = $this->db->get();
助けてくれてありがとう。