2015-09-07 41 views
0

我正在为摄影业务创建一个PHP购物车。这是第一个电子商务网站,我已经尝试(新手)PHP购物车 - 添加变量

我已成功将产品添加到购物车(保存在session) (产品:打印,钥匙扣,磁铁ECT)

但是我还需要以图像标识添加到会话

这里是我的代码

$product_id = $_GET[id];  //the product id from the URL 
    $imageId = $_GET[imageid]; //the image id from the URL 
    $action  = $_GET[action]; //the action from the URL 

    switch($action) { //decide what to do 

     case "add": 
      $_SESSION['cart'][$product_id]++; //add one to the quantity of the product with id $product_id 
     break; 

该产品保存到篮下 enter image description here

的cart.php URL被示出为:

cart.php图像标识= 83 & ID = 12 &行动=添加

任何人都可以帮助/指教我怎样添加图片ID到产品?

谢谢

+0

通过_“将图像ID添加到产品中”_是否将它存储在会话中或将图像显示在篮子中? –

+0

我的意思是两个...... – Shane

+0

你可以显示生成篮子标记的代码吗? –

回答

1

这是假设一个图像可以被不同的产品使用?否则,你应该仅仅是能够推断出使用基于该图像上的产品ID:

case "add": 
    $_SESSION['cart'][$product_id]++; //add one to the quantity of the product with id $product_id 
    $_SESSION['images'][$product_id] = $imageId; //Will map the image ID to the product being added 
break; 

无论如何,没有看到实际的标记,添加图像到篮下应该是这样的:

<basket element> 
    <item element> 
     <img src="path/to/images/<?=$_SESSION['images'][$product_id]?>.filetype" /> 
    </item> 
</basket>