首先在index.php里最后加一个函数,
大概如下:
function getMostClickGoods($cat,$sum){
$sql = " select * from ". $GLOBALS['ecs']->table('goods') ." where is_delete=0 and (" . get_children($cats) . " OR " . get_extension_goods($cats) .") order by click_count";
$res = $GLOBALS['db']->selectLimit($sql, $sum,0);
$idx = 0;
$goods = array();
while ($row = $GLOBALS['db']->fetchRow($res))
{
$goods[$idx]['id'] = $row['goods_id'];
$goods[$idx]['name'] = $row['goods_name'];
$goods[$idx]['catname'] = $row['cat_name'];
$goods[$idx]['caturl'] = build_uri('category', array('cid'=> $row['cat_id']));
$goods[$idx]['brief'] = $row['goods_brief'];
$goods[$idx]['brand_name'] = $row['brand_name'];
$goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
$goods[$idx]['market_price'] = price_format($row['market_price']);
$goods[$idx]['shop_price'] = price_format($row['shop_price']);
}
return $goods;
}
接下来就是调用了,
$smarty->assign('most_click_goods', getMostClickGoods(22,8));
然后就是在index.dwt里,这时就像循环其它数组变量一样,使用smarty标签循环这个变量即可。
<!-- {foreach from=$most_click_goods item=goods}-->
<div class="clickgoodslist">
<a href="/{$goods.url}" title="{$goods.name|escape:html}"><img src="/{$goods.goods_img}" alt="{$goods.name|escape:html}"/></a></div>
<!--{/foreach}-->