doudui2229 2014-05-14 08:20
浏览 68
已采纳

用PHP,JavaScript和Html创建一个简单的购物车?

I am attempting to create a shopping cart using PHP for a Shirt Design Website. Users can design the shirts and then add them to the cart. So I created a form, in which users can pick their colour and sizes:

<form action="cart_main.php">
    <table>
        <tr><td>Colour:</td><td> <select>
        <option value="Blue">Blue</option>
        <option value="Red">Red</option>
        <option value="Pink">Pink</option>
        <option value="Black">Black</option>
        <option value="Grey">Grey</option>
        <option value="Beige">Beige</option>
        <option value="White">White</option>
        </select></td></tr>

        <tr><td>Design:</td><td> <select>
        <option value="T1">Skull</option>
        <option value="T2">Liquify</option>
        <option value="T3">Wings</option>
        <option value="T4">Small Skull</option>
        <option value="T5">Cogs</option>
        <option value="T6">Safety Pin</option>
        </select></td></tr>

        <tr><td>Pop Colour: </td><td> <select>
        <option value="Blue">Blue</option>
        <option value="Red">Red</option>            
        <option value="Yellow">Yellow</option>
        <option value="Purple">Purple</option>
        </select></td></tr>
        <tr><td><button id="addToCart" name="addToCart">Add to Cart</button></td></tr>

</table>
</form>

I need to simply create a shopping cart that will display all of the added items and total price when viewed by the user. This wouldn't be too hard, if it was a single value, but since I need to send/store 3 values; Colour, Design and Pop Colour, I am not sure how i should do it.

I have tried:

> Sending the selected data to a table in a database. And then getting the whole table when viewing the Cart
> Using javascript to Find the ID of a shirt depending of what has been selected (Failed)

So my QUESTION is:

How would i create a shopping cart for something like this in the simplest manner. Or how do i send multiple values accross and group them so i can create a cart.

Thank you Very Much!!

  • 写回答

1条回答 默认 最新

  • doushen4719 2014-05-14 08:31
    关注

    Steps to create shopping cart:

    1) Have an object to store the values eg. product

    product = { 
    // product properties
    
    color: "color", 
    design: "skull", 
    popColor: "color"
    }
    

    2) On submit of the form, in cart_main.php fetch the values and populate in the product object

    3) You need to have a cart array.

    4) To that cart array, add the object. So now you have list of objects inside the cart array.

    In the UI you just need to show the count of objects in the array.

    When they cart is clicked, you need to iterate the objects and populate the properties

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决