私は次のようなデータベース設定をしています:
post_id | タイトル
1 | いくつかのタイトル
2 | 別のタイトル
tag_id | 鬼ごっこ
1 | tag01
2 | tag02
post_id | tagt_id
1 | 1
1 | 2
2 | 1
私はこれらのテーブルを次のコードで結合しました:
$this->db->select('*');
$this->db->from('posts');
$this->db->join('posts_tags', 'posts.post_id = post_tags.post_id', 'inner');
$this->db->join('tags', 'posts_tags.tag_id = tags.tag_id', 'inner');
私の見解では、を使用してタグにアクセスできます
$post['tag']
これにより、関連付けられているすべてのタグの投稿が重複します。
問題は、1つの投稿に関連付けられているすべてのタグをどのようにループするかです。
期待される出力は次のようになります。
post_id 1 = tag01、tag02
それ以外の
post_id 1 = tag01
post_id 1 = tag02