ecshop增長 瀏覽過該商品的人還瀏覽了那些商品 功能

這個 功能比較簡單 可是須要增長一個 數據


  1. CREATE TABLE `sc_history` (
  2. `id` int(10) unsigned NOT NULL auto_increment,
  3. `user_id` int(10) unsigned NOT NULL,
  4. `goods_id` int(10) NOT NULL,
  5. PRIMARY KEY (`id`)
  6. ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
複製代碼



首先在goods.php中找到


  1. /*更新瀏覽歷史*/
  2. $sql = 「select count(*) from 「.$GLOBALS['ecs']->table(‘history’).」 where goods_id=’$goods_id’」;
  3. $num = $GLOBALS['db']->getOne($sql);
  4. if(empty($num)){
  5. $user_id = !empty($_SESSION['user_id'])?intval($_SESSION['user_id']):0;
  6. $sql = 「insert into 「.$GLOBALS['ecs']->table(‘history’).」 (goods_id,user_id) values(‘$goods_id’,'$user_id’)」;
  7. $GLOBALS['db']->query($sql);
  8. }
複製代碼


將瀏覽商品放入 數據庫
在 lib_insert中增長一個函數

  1. insert_db_history();
  2. function insert_db_history()
  3. {
  4. $str = 」;
  5. $res = array();
  6. $sql = 「select goods_id from 「.$GLOBALS['ecs']->table(‘history’);
  7. $res = $GLOBALS['db']->getAll($sql);
  8. $ins = 」;
  9. foreach($res as $key=>$val){
  10. $ins .= $val['goods_id'].’,';
  11. }
  12. $ins = rtrim($ins,’,');
  13. if (!empty($ins))
  14. {
  15. $where = db_create_in($ins, ‘goods_id’);
  16. $sql = ‘SELECT goods_id, goods_name, goods_thumb, shop_price FROM ‘ . $GLOBALS['ecs']->table(‘goods’) .
  17. 」 WHERE $where AND is_on_sale = 1 AND is_alone_sale = 1 AND is_delete = 0″;
  18. $query = $GLOBALS['db']->query($sql);
  19. $res = array();
  20. while ($row = $GLOBALS['db']->fetch_array($query))
  21. {
  22. $goods['goods_id'] = $row['goods_id'];
  23. $goods['goods_name'] = $row['goods_name'];
  24. $goods['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
  25. $goods['goods_thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
  26. $goods['shop_price'] = price_format($row['shop_price']);
  27. $goods['url'] = build_uri(‘goods’, array(‘gid’=>$row['goods_id']), $row['goods_name']);
  28. $res[] = $goods;
  29. }
  30. }
  31. $GLOBALS['smarty']->assign(‘db_history’,$res);//
  32. $output = $GLOBALS['smarty']->fetch(‘library/db_history.lbi’);
  33. return $output;
  34. }
複製代碼



在增長一個db_history.lbi就完成了 全部功能了。
若是你想添加到任何 頁面的話 值須要將{insert name=」db_history」}增長到你須要的位置就能夠了。
可是這個功能會致使你的數據表一直增長,因此適用於商品不是太多的 網站,若是商品多的話只要定時更新數據表便可。
相關文章
相關標籤/搜索