私はこれらの2つのテーブルを持っています:
sections - {id,title,description}
topics - {id,section_id,topictitle}
各セクションには、トピックテーブルに複数のトピックがあります。
読んで試した後、左結合を使用するのが正しい方法であることがわかりました
$sql = 'select * from sections left join topics on sections.id=topics.sections_id';
$query = mysql_query($sql);
$section = array();
$i=0;
while ($sections = mysql_fetch_assoc($query)) {
$sl = array(
'title' => $sections['title'],
'topics'=> $sections['topictitle'],
);
$section[$i++] = $sl;
}
これは、すべてのセクションとトピックを表示するための正しいコードですか?