gpt4 book ai didi

php - 类别和子类别

转载 作者:行者123 更新时间:2023-11-29 23:04:46 24 4
gpt4 key购买 nike

我对类别和子类别有疑问。我无法获取与类别相同的category_id 中的子类别数据。我定义子类别category_id的方式与类别category_id相同,子类别父级是2。

Database is here

<?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>
-->

最佳答案

在 While 循环中,您必须包含另一个查询来获取特定类别的子类别(从 id 字段获取子类别后),即父级是某个类别 ID。

关于php - 类别和子类别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28344143/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com