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

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

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法