我遇到类别和子类别的问题。我不能将category_id中的子类别数据作为类别获取。我如何定义子类别category_id与类别category_id相同,子类别parent为2.
<?php
//connect to Mysql database
include "storescripts/connect_to_mysql.php";
// This block grabs the whole list for viewing
$dynamic_menu = "";
$sql = mysql_query("SELECT * FROM `category` WHERE `parent` IS NULL ORDER BY `category`.`name` ASC");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0)
{
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$name = $row["name"];
$parent = $row["parent"];
$category_id = $row["category_id"];
$dynamic_menu .= '<div class="menu-primary">
<li><a>'.$name.'</a></li></div>
<div class="menu-under">
<li><a>'.$name.'</a></li>
</div>';
}} else {
$dynamic_menu = "You have no products listed in our store yet";
}
?>
<div class="menu">
<?php echo $dynamic_menu; ?>
</div>
<!--
I'd like to html created like below
<div class="menu-primary">
<li><a>Kaamerad</a></li>
</div>
<div class="menu-under">
<ul>
<li><a>optikad</a></li>
<li><a>mälukaardid</a></li>
</ul>
</div>
-->
答案 0 :(得分:0)
在While循环中,您必须包含另一个查询以获取特定类别的子类别(在从id字段获取子类别之后),即父级是特定类别Id的位置。
答案 1 :(得分:0)