我有这两张表:
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;
}
这是查看所有部分和主题的正确代码吗?