doupinge9055 2015-09-07 11:27 采纳率: 100%
浏览 36
已采纳

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 enter image description here

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

  • 写回答

1条回答 默认 最新

  • douzhi3667 2015-09-07 11:54
    关注

    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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么