这个
功能比较简单 可是须要增长一个
数据表
- 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”}增长到你须要的位置就能够了。
可是这个功能会致使你的数据表一直增长,因此适用于商品不是太多的
网站,若是商品多的话只要定时更新数据表便可。