最近浏览记录最后点击的一条无法显示怎么回事
倒最后一条的前一条记录显示了,各位哪里出了问题最近浏览的5条记录现在程序问题是,显示了最后点击的这条记录后面的5条记录了。不明白问题出在哪里$action=$_GET["action"];
$temp=$_COOKIE["last_product_view"];
if($action==1){
if(is_array($temp)){
$ar=array_keys($temp);
if(count($ar)==6)
{
array_pop($ar);
}
for($i=count($ar)-1;$i>=0;$i--){
echo "<li>".count($ar)."<a href=\"/website/html/product/show_pro_".$temp["$ar[$i]"].".html\" target=\"_blank\">".str_replace("__"," ",$ar[$i])."</a></li>\n";
}
}else{
echo "Nothing";
}
}elseif($action==0){
if($_GET["name"]!=""&&$_GET["link"]!=""){
if(is_array($temp)){
$ar=array_keys($temp);if(count($temp)==6)
{
array_pop($temp);
if(in_array("last_product_view[".$ar[0]."]",$temp,true))
{
array_unique($temp,"last_product_view[".$ar[0]."]");
each($temp,"last_product_view[".$ar[0]."]");
}
if(in_array("last_product_view[".$ar[0]."]",$temp,false))
{
array_unshift($temp,"last_product_view[".$ar[0]."]");
}
else
{
setcookie("last_product_view[".$ar[0]."]","",time()-3600);
array_unshift($temp,"last_product_view[".$ar[0]."]");
}
}
}
$cookie_names=str_replace(" ","__",js_unescape($_GET["name"]));
setcookie("last_product_view[".$cookie_names."]",$_GET["link"],time()+3600,"/");
}
}
倒最后一条的前一条记录显示了,各位哪里出了问题最近浏览的5条记录现在程序问题是,显示了最后点击的这条记录后面的5条记录了。不明白问题出在哪里$action=$_GET["action"];
$temp=$_COOKIE["last_product_view"];
if($action==1){
if(is_array($temp)){
$ar=array_keys($temp);
if(count($ar)==6)
{
array_pop($ar);
}
for($i=count($ar)-1;$i>=0;$i--){
echo "<li>".count($ar)."<a href=\"/website/html/product/show_pro_".$temp["$ar[$i]"].".html\" target=\"_blank\">".str_replace("__"," ",$ar[$i])."</a></li>\n";
}
}else{
echo "Nothing";
}
}elseif($action==0){
if($_GET["name"]!=""&&$_GET["link"]!=""){
if(is_array($temp)){
$ar=array_keys($temp);if(count($temp)==6)
{
array_pop($temp);
if(in_array("last_product_view[".$ar[0]."]",$temp,true))
{
array_unique($temp,"last_product_view[".$ar[0]."]");
each($temp,"last_product_view[".$ar[0]."]");
}
if(in_array("last_product_view[".$ar[0]."]",$temp,false))
{
array_unshift($temp,"last_product_view[".$ar[0]."]");
}
else
{
setcookie("last_product_view[".$ar[0]."]","",time()-3600);
array_unshift($temp,"last_product_view[".$ar[0]."]");
}
}
}
$cookie_names=str_replace(" ","__",js_unescape($_GET["name"]));
setcookie("last_product_view[".$cookie_names."]",$_GET["link"],time()+3600,"/");
}
}
你提了三次问题,我现在才明白,楼主的意思??楼主是否是想根据点击的Cookies的生成时间来判断,对吗???如果是这种思想,好像是不行的。
也就是显示最近浏览的5条记录。上面的程序已经实现显示最近记录
但是最后的一条没有被显示。
也就是比如
A,B,C
3条记录点击A,A加入cookie
点击B,B加入cookie
.............但是现在点击A,A记录没有显示
点击b的时候才显示了a这样总少一条记录在数组里面
怪不得了,if(count($ar)==6)
{
array_pop($ar);
} 这段代码是错误的根源。如果判断成立,那就删除了最后一个元素,那么在下面的第一次循环就没有了啊。修改后的代码:
$action=$_GET["action"];
$temp=$_COOKIE["last_product_view"];
if($action==1){
if(is_array($temp)){
if(count($ar)==6)//把它提前嘛,就不会有冲突。
{
array_pop($ar);
}
$ar=array_keys($temp);
for($i=count($ar)-1;$i>=0;$i--){
echo " <li>".count($ar)." <a href=\"/website/html/product/show_pro_".$temp["$ar[$i]"].".html\" target=\"_blank\">".str_replace("__"," ",$ar[$i])." </a> </li>\n";
}
}else{
echo "Nothing";
}
}elseif($action==0){
if($_GET["name"]!=""&&$_GET["link"]!=""){
if(is_array($temp)){
$ar=array_keys($temp);if(count($temp)==6)
{
array_pop($temp);
if(in_array("last_product_view[".$ar[0]."]",$temp,true))
{
array_unique($temp,"last_product_view[".$ar[0]."]");
each($temp,"last_product_view[".$ar[0]."]");
}if(in_array("last_product_view[".$ar[0]."]",$temp,false))
{
array_unshift($temp,"last_product_view[".$ar[0]."]");
}else
{
setcookie("last_product_view[".$ar[0]."]","",time()-3600);
array_unshift($temp,"last_product_view[".$ar[0]."]");
}
}
}
$cookie_names=str_replace(" ","__",js_unescape($_GET["name"]));
setcookie("last_product_view[".$cookie_names."]",$_GET["link"],time()+3600,"/");
}
}
if(count($ar)==6)
{
array_pop($ar);
}
新加就是6条
如果有重复就是5条
if(count($temp)==6)
{
array_pop($temp);
if(in_array("last_product_view[".$ar[0]."]",$temp,true))
{
array_unique($temp,"last_product_view[".$ar[0]."]");
each($temp,"last_product_view[".$ar[0]."]");
} if(in_array("last_product_view[".$ar[0]."]",$temp,false))
{
array_unshift($temp,"last_product_view[".$ar[0]."]");
} else
应该是这个地方的问题
怎么把它写成if else是个问题
同样道理,把
$ar=array_keys($temp);if(count($temp)==6)
{
array_pop($temp);
这部分代码改为:if(count($temp)==6)
{
array_pop($temp);
$ar=array_keys($temp);