PHP购物车 - 添加变量
I am creating a PHP cart for a photography business. This is the 1st Ecommerce site I have attempted (Newbie)
I have managed to add products to the cart (stored in the session) (Products: Print, Keyring, Magnet ect)
However I also need to add the imageID to the session
Here is my code
$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;
Which saves the product to the basket
The cart.php url is shown as:
cart.php?imageid=83&id=12&action=add
Could anyone help/advise how I add the Image ID to the product?
Thanks
我正在为摄影业务创建一个PHP购物车。 这是我尝试的第一个电子商务网站(新手) p>
我已设法将产品添加到购物车(存储在会话中) (产品:打印,钥匙圈,磁铁等) p>
但是我还需要将imageID添加到会话中 p>
这是我的代码 p>
$ product_id = $ _GET [id]; //来自URL的产品ID
$ imageId = $ _GET [imageid]; //来自URL的图像ID
$ action = $ _GET [action]; //来自URL
开关的动作($ action){//决定做什么
case“add”:
$ _SESSION ['cart'] [$ product_id] ++; //在产品数量上添加一个ID为$ product_id
break;
code> pre>
cart.php网址显示为: p>
cart.php?imageid = 83& id = 12& action = add p>
blockquote>
有人可以帮助/建议我如何将图像ID添加到产品中吗? p>
谢谢 p>
div>
This is assuming one image can be used by different products? Otherwise, you should simply be able to deduce which image to use based on the product 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;
Anyway, without seeing your actual markup, adding the image to the basket should be something like:
<basket element>
<item element>
<img src="path/to/images/<?=$_SESSION['images'][$product_id]?>.filetype" />
</item>
</basket>