I'm building a custom shopping cart for a supermarket with php, mysql and smarty template the products categories and sub categories must be in tow separate tables categories table (id, catname) subcategories table (id,cat_id,subcategory) where cat_id refers to the category let say I have 2 categories and 2 subcategories for each category my php code is
$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");
and my html code is:
{section name=cats loop=$category_link}
<div class="category">{$category_link[cats].catname}</div>
{/section}
How could I view each sub-category below the category it belongs to?? like:
<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>
Regards