我大约有5种用餐类别,例如“ M01”(“ M”代表膳食),“ B01”(“ B”代表平均消费)等等。我要在前端的每个类别页面中,而不是在一页中显示所有内容,我想根据产品的类别对产品进行排序,例如在“ Baverages”页面中,“ B01”类别代码下将有一个Baverages列表。如何使用PHP和MySQLi实现这一目标?对不起,简单的代码,我还是这个新手。预先感谢!
这是我的代码:
<table class="table-list">
<tbody id="mealTable">
<?php
$result=mysqli_query($conn,"SELECT * FROM meal");
$row_count = mysqli_num_rows($result);
if ($row_count == 0) { ?>
<tr>
<td colspan = "6">
<?php echo "No data found"; ?>
</td>
</tr>
<?php } else {
while($row = mysqli_fetch_array($result)) { ?>
<tr>
<td><?php echo $row['meal_name']?></td>
<td>RM <?php echo $row['meal_price']?></td>
<td ><a href="addtocart.php?mid=<?php echo $row['meal_id']; ?>" style="background-color: green; color: white; padding: 10px 10px; text-align: center; text-decoration: none; display: inline-block;font-size: 14px; width: 70px; height: 13px; ">Add To Cart</a>
</td>
</tr>
<?php } }
?>
</div>