首页 > 其他 > 详细

商品的浏览记录

时间:2019-06-20 17:00:34      阅读:129      评论:0      收藏:0      [点我收藏+]
技术分享图片

 


原理:把点击过的商品的goods_id放入 cook==1,2,4,3,5 ;

   从数据库查询商品id在1,2,4,3,5中的商品分配到模版页
如果cook没有设置cook
如果有追加,去重,如果大于5,pop   

1
session_start(); 3 //商品的浏览记录 4 $goods_id=mt_rand(1,10); 5 if(empty($_COOKIE[‘user‘][‘history‘])){ 6 setcookie(‘user[history]‘,$goods_id,time()+3600*24*30); 7 }else{ 8 $hisOld=$_COOKIE[‘user‘][‘history‘]; 9 $hisArray=explode(‘,‘,$hisOld); 10 array_unshift($hisArray,$goods_id); 11 $hisArray=array_unique($hisArray); 12 if(count($hisArray)>5){ 13 array_pop($hisArray); 14 } 15 $goods_id=implode(‘,‘,$hisArray); 16 setcookie(‘user[history]‘,$goods_id,time()+3600*24*30); 17 p($_COOKIE[‘user‘][‘history‘]); 18 } 19 //传浏览记录 20 $history= $_COOKIE[‘user‘][‘history‘];// 1,7,2,9,3 21 $history = $db->getAll("select * from goods where goods_id in ({$history})"); 22 $tpl->assign(‘history‘,$history); 23 24 //过程 25 //goods_id=1 26 1 //如果没有,设置cook=1(goods_id) 27 [0=>1] //如果有把cook里的值分割成数组 //1,2,3,4,5 28 [1=>2,0=>1]//在数组的前边插入新浏览的记录,形成新的数组 29 //去重,判断count(cook)>5则pop 30 2,1 //在把新形成的数组变为字符串放入cook//2,1,3,4,5,

 

商品的浏览记录

原文:https://www.cnblogs.com/finddata/p/11059685.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!