2015-09-07 42 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>