我现在在用PHP做购物车,功能都实现了 就是还有一个地方不行,就是客户在选商品点击图片进入购物车,主要就是购物车只能显示一个商品的图片 在点击另一个商品时 就出错了!!!现实不出来 这一点需要怎么做怎么写呢?<img src="../uploadImg/productImg/<?php echo $val['url'];?> " border="0" alt="" width="100px" height="100px"/>这是购物车显示商品图片那个代码!
调试欢乐多
类似这样组织自己的数据结构
别的方法也不应该有问题。总归就是个商品列表,如果该商品有图片的话
foreach 循环不会有问题的。
if(isset($_SESSION['userid']))
{
$userid =$_SESSION['userid'];
echo $productid;if(!empty($_GET['productid']))
{
$productid=$_GET['productid'];
$num=0;
echo $productid;
$ordersql="select id from orders where customer_id=$userid ";
$or_result=mysql_query($ordersql);
$or_row=mysql_fetch_row($or_result);
if(!$or_row[0])
{
$ordersql="insert into orders(customer_id,date)values(".$_SESSION['userid'].",NOW())";
mysql_query($ordersql);
$_SESSION['orderid']=mysql_insert_id();
$itemsql="insert into order_items(order_id,product_id,quantity) values(".$_SESSION['orderid'].",$productid,$num)";
mysql_query($itemsql);}
else
{
$itemsql="insert into order_items(order_id,product_id,quantity) values($or_row[0],$productid,$num)";
mysql_query($itemsql);
}
}
$sql="select oi.id,p.name,p.price,oi.quantity,p.image from products p,orders o,order_items oi,customers c where oi.order_id=o.id and oi.product_id=p.id and c.id=o.customer_id and c.id=$userid";
$result=mysql_query($sql);
$number=mysql_num_rows($result);
$row=mysql_fetch_row($result);
$total=0;
while($row)
{
echo "
<ul style="."float:left; margin-top:20px; margin-left:5px;".">
<li style="."float:left;"."><a href="."#"."><img src="."$row[4]"." width=40 height=40 /></a></li>
<li style="."float:left; margin-left:20px;"."><a href="."#"." style="."color:#FFFFFF; font-size:14px;".">平板显示器 戴尔 型号123 - E7</a></li>
<li style="."margin-top:30px;"."><a href="."#"." style="."color:#FFFFFF; font-size:13px;".">产品型号:PX-100</a></li>
</ul>
<ul style="."float:left; margin-top:50px;".">
<li style="."color:#FFFFFF;".">产品价格:$row[2]</li>
</ul>
<ul style="."float:left; margin-top:50px; margin-left:20px;".">
<li style="."color:#FFFFFF;".">
<label>选择数量:
<input name="."textfield"." type="."text"." value=1 />
</label>
</li>
<li>
<a href="."delete.php?id=$row[0]".">删除</a>
</li>
</ul>";
$total=$total + $row[2]*$row[3];
$updatesql="update orders,customers set total=$total where customers.id=orders.customer_id and customers.id= $userid";
mysql_query($updatesql);
$row=mysql_fetch_row($result);
}
}
else
echo "您还没登陆";
?>