我有3个表存储rest_categories,rest_type和rest_dish cat_id是rest_type&中的FK。 rest_dish ty_id也是rest_dish中的FK。
当我尝试使用while循环显示它时,它只显示第一条记录
。 代码:
<?php
$cat_ct = mysql_query("SELECT COUNT(cat_name) FROM rest_categories;");
$cat = mysql_query("SELECT * FROM rest_categories");
while ($row = mysql_fetch_array($cat))
{
$cat_id = $row["cat_id"];
$cat_name = $row["cat_name"];
?>
<h2><?php echo "$cat_name"; ?></h2>
<?php
$ty_ct = mysql_query("SELECT COUNT(ty_name) FROM rest_type;");
$cat = mysql_query("SELECT * FROM rest_type where cat_id='$cat_id'");
while ($row = mysql_fetch_array($cat))
{
$ty_id = $row["ty_id"];
$ty_name = $row["ty_name"];
?>
<h3> <?php echo "$ty_name"; ?> </h3>
<br>
<?php
$dish_ct = mysql_query("SELECT COUNT(dish_name) FROM rest_dish;");
$cat = mysql_query("SELECT * FROM rest_dish where cat_id='$cat_id' and ty_id='$ty_id'");
while ($row = mysql_fetch_array($cat))
{
$dish_id = $row["dish_id"];
$dish_price = $row["online_price"];
$dish_name = $row["dish_name"];
?>
<div class="wrapper pad_bot1">
<table>
<tr>
<td>
<?php echo "$dish_name"; ?> </td>
<td>           <?php echo "$dish_price"; ?> </td>
</tr>
</div>
</table>
<?php }
}
} ?>
</section>
</div>
</article>
</div>
答案 0 :(得分:1)
您的$cat
已在内循环中被替换。只需删除这些冲突。