我有 2 张桌子:
categories (id, categoryName)
,
menu (id, menuname, category_id)
我想显示所有类别,在menu
. 并且每次categoryName
显示 5之后menuname
。
是否可以在一个记录集中执行此操作?
谢谢!
这些是我的 2 个记录集:
$query = "select a.id, a.name from categories as a where a.id in (select count(*) from menu as b on b.category_id = a.id)";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
echo $row['name'];
$category_id = intval($row['id']);
$query = "select menuname from menu where category_id = $category_id limit 0, 5";
$resultmenu = mysql_query($query);
while ($rowmenu = mysql_fetch_array($resultmenu)) {
echo $rowmenu['menuname'];
}
}