php购物车
首页 购物篮 历史记录 退出
<?php
$con = mysql_connect("localhost", "root", "");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db("user",$con);
$sql="select * from produce";//查询所有商品
$rs=mysql_query($sql,$con);//执行sql语句,得到一个结果集
while($row=mysql_fetch_array($rs))//遍历结果集
{
?>
src="images/<?php echo $row["pimg"]?>" width="123" style="max-width:90%" border="0" /> | 货物名称:<?php echo $row["pname"] ?> |
货物价格:<?php echo $row["price"] ?> | |
&pname=<?php echo $row["pname"] ?>">购买 |
<?php
}
?>
------解决方案--------------------
你想提问的是什么? 有个 编码 方式的 文本。
你把内容用相应的源码高亮显示不是更方便别人为你解决问题吗?
------解决方案--------------------
<?php
$act=$_GET[act];
$product_id=$_GET[prcid];
if($act=="add")
{
$cars_id=explode(",",$_COOKIE[buypro]);
//echo "
";";
//print_r($cars_id);
//echo"
//exit;
foreach($cars_id as $pr_id)
{
if($pr_id==$product_id)
{
echo "";
exit;
}
}
if(empty($_COOKIE[buypro]))
{
setcookie("buypro",$product_id,time()+3600);
setcookie("buycount","1",time()+3600);
}
else
{
$newpro=$_COOKIE[buypro].",".$product_id;
$newcount=$_COOKIE[buycount].","."1";
setcookie("buypro",$newpro,time()+3600);
setcookie("buycount",$newcount,time()+3600);
}
}
//删除
if($act=="del")
{
$buy=$_COOKIE[buypro];
$cars_id=explode(",",$buy);
$buycountary=explode(",",$_COOKIE[buycount]);
$newid=array();
$carcount=array();
for($i=0;$i
if($cars_id[$i]!=$product_id)
{
$newid[]=$cars_id[$i];
$carcount[]=$buycountary[$i];
}
}