【发布时间】:2016-07-28 00:20:24
【问题描述】:
我希望能够通过 SQL 查询选择发布到某个类别的最新主题。
我有两个要使用的表。
- 类别
- 主题
主题行知道它属于哪个类别,因为topics.topic_cat 应该与categories.cat_id 匹配。
我想遍历所有类别并显示发布给它们的最新主题。它看起来像这样。
while($row = $result->fetch_assoc()) {
echo $row['cat_name'] . ' Latest Post is ' . $row['topic_name'];
}
这将是执行后的外观示例。
category1 Latest Post is "latest post"
category2 Latest Post is "latest post"
category3 Latest Post is "latest post"
等等……
我可以使用什么 SQL 查询来选择它?
这是我的表结构。
类别
- cat_id
- 猫名
- cat_description
主题
- topic_id
- 主题名称
- 主题日期
- topic_cat
- topic_by
【问题讨论】:
-
请张贴您的表格结构。
-
@RobertColumbia 我已经发布了它们,这些信息是否足够?如果您需要更多,请询问我。