我正在使用 php、mysql 和 smarty 模板为超市构建自定义购物车产品类别和子类别必须在两个单独的表中类别表(id,catname)子类别表(id,cat_id,subcategory)其中 cat_id 指类别假设我的 php 代码是每个类别有 2 个类别和 2 个子类别
$smarty = new Smarty;
$smarty->caching = true;
$smarty->cache_lifetime = 120;
$category_mysql = "SELECT * FROM category";
$run_category = mysql_query($category_mysql, $link) or die(mysql_error());
$all_category = mysql_num_rows($run_category);
$category_link = array();
$i=0;
while ($category = mysql_fetch_assoc($run_category)) {
$ml = array(
'id' => $category['id'],
'catname'=> $category['catname'],
);
$category_link[$i++] = $ml;
}
$smarty->assign('category_link', $category_link);
$smarty->display("products.tpl");
我的html代码是:
{section name=cats loop=$category_link}
<div class="category">{$category_link[cats].catname}</div>
{/section}
我如何查看其所属类别下方的每个子类别?像:
<div class="category">Category 1</div>
<div class="subcat">Sub Cat 1</div>
<div class="subcat">Sub Cat 2</div>
<div class="category">Category 2</div>
<div class="subcat">Sub Cat 3</div>
<div class="subcat">Sub Cat 4</div>
问候