這個
功能比較簡單 可是須要增長一個
數據表
- CREATE TABLE `sc_history` (
- `id` int(10) unsigned NOT NULL auto_increment,
- `user_id` int(10) unsigned NOT NULL,
- `goods_id` int(10) NOT NULL,
- PRIMARY KEY (`id`)
- ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
複製代碼
首先在goods.php中找到
- /*更新瀏覽歷史*/
- $sql = 「select count(*) from 「.$GLOBALS['ecs']->table(‘history’).」 where goods_id=’$goods_id’」;
- $num = $GLOBALS['db']->getOne($sql);
- if(empty($num)){
- $user_id = !empty($_SESSION['user_id'])?intval($_SESSION['user_id']):0;
- $sql = 「insert into 「.$GLOBALS['ecs']->table(‘history’).」 (goods_id,user_id) values(‘$goods_id’,'$user_id’)」;
- $GLOBALS['db']->query($sql);
- }
複製代碼
將瀏覽的
商品放入
數據庫。
在 lib_insert中增長一個函數
- insert_db_history();
- function insert_db_history()
- {
- $str = 」;
- $res = array();
- $sql = 「select goods_id from 「.$GLOBALS['ecs']->table(‘history’);
- $res = $GLOBALS['db']->getAll($sql);
- $ins = 」;
- foreach($res as $key=>$val){
- $ins .= $val['goods_id'].’,';
- }
- $ins = rtrim($ins,’,');
- if (!empty($ins))
- {
- $where = db_create_in($ins, ‘goods_id’);
- $sql = ‘SELECT goods_id, goods_name, goods_thumb, shop_price FROM ‘ . $GLOBALS['ecs']->table(‘goods’) .
- 」 WHERE $where AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0″;
- $query = $GLOBALS['db']->query($sql);
- $res = array();
- while ($row = $GLOBALS['db']->fetch_array($query))
- {
- $goods['goods_id'] = $row['goods_id'];
- $goods['goods_name'] = $row['goods_name'];
- $goods['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
- $goods['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
- $goods['shop_price'] = price_format($row['shop_price']);
- $goods['url'] = build_uri(‘goods’, array(‘gid’=>$row['goods_id']), $row['goods_name']);
- $res[] = $goods;
- }
- }
- $GLOBALS['smarty']->assign(‘db_history’,$res);//
- $output = $GLOBALS['smarty']->fetch(‘library/db_history.lbi’);
- return $output;
- }
複製代碼
在增長一個db_history.lbi就完成了 全部功能了。
若是你想添加到任何
頁面的話
值須要將{insert name=」db_history」}增長到你須要的位置就能夠了。
可是這個功能會致使你的數據表一直增長,因此適用於商品不是太多的
網站,若是商品多的話只要定時更新數據表便可。