取值
- $sql = "SELECT * FROM " . $dou->table('product_category') . " WHERE cat_id = '$cat_id'";
- $query = $dou->query($sql);
- $cate_info = $dou->fetch_assoc($query);
赋值
- $smarty->assign('parent_id', $cate_info['parent_id']);
前台根据parent_id判断
- <!-- {if $parent_id eq 0} -->
- <!-- {foreach from=$product_category2 item=cate} -->
- <li<!-- {if $cate.cur} --> class="cur"<!-- {/if} -->><a href="{$cate.url}">{$cate.cat_name}</a></li>
- <!--{/foreach}-->
- <!-- {else} -->
- <!-- {foreach from=$product_category item=cate} -->
- <li<!-- {if $cate.cur} --> class="cur"<!-- {/if} -->><a href="{$cate.url}">{$cate.cat_name}</a></li>
- <!--{/foreach}-->
- <!-- {/if} -->
解析
- $smarty->assign('product_category', $dou->get_category('product_category', $cate_info['parent_id'], $cat_id));
- $smarty->assign('product_category2', $dou->get_category('product_category', $cat_id, $cat_id));