首頁  >  文章  >  後端開發  >  关于购物车实现的小问题 谢谢大家

关于购物车实现的小问题 谢谢大家

WBOY
WBOY原創
2016-06-20 12:35:40897瀏覽

session_start();
include("conn/conn.php");
if($_SESSION[username]==""){
  echo "<script>alert('请先登录后购物!');history.back();</script>"; 
  exit;
 }
$id=strval($_GET[id]);
$sql=mysql_query("select * from tb_shangpin where id='".$id."'",$conn); 
$info=mysql_fetch_array($sql);
if($info[shuliang]   echo "<script>alert('该商品已经售完!');history.back();</script>";
   exit;
 }
  $array=explode("@",$_SESSION[producelist]);
  for($i=0;$i  if($array[$i]==$id){
     echo "<script>alert('该商品已经在您的购物车中!');history.back();</script>";
 exit;
  }
}
  $_SESSION[producelist]=$_SESSION[producelist].$id."@";
  $_SESSION[quatity]=$_SESSION[quatity]."1@";
  header("location:gouwu1.php");
?> 
上面的count ($array)为什么还要减一啊谢谢大家


回复讨论(解决方案)

因为每次增加商品时:$_SESSION[producelist]=$_SESSION[producelist].$id."@";
$_SESSION[producelist] 的内容以 @ 结束
explode 后,$array 最后一个元素为空

因为每次增加商品时:$_SESSION[producelist]=$_SESSION[producelist].$id."@";
$_SESSION[producelist] 的内容以 @ 结束
explode 后,$array 最后一个元素为空

真心谢谢你
陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn