again , for learning purpose i want a very basic shopping cart without all the extras (security or money transaction, just updating D😎, i have scanned thorugh this forum and other material and it's not clear what is happening. i understand programming concepts but a begginer in php.

Below is an example (there is no money involved, just update database), which i have over simplified so i understand, all other threads discussing shopping basket are too advanced for me and i get lost in them. Specific questions follows:

A website with 2 types of products, lets say, vegtables and fuits.

  1. "veg.php" page retrieves and displays from a database table called veg, all the veggie products in that table, so carrots, potatoes, etc. the columns displayed will be Name and Quantity.

  2. similary, "fruits.php" retrieves from a database table called fruits, all fruits products in that table.

  3. Each results row has next to it "Add to basket".

  4. when you press "Add to basket" that particular product and qty is added to basket

  5. the person can switch from veg.php and fruits.php pages at anytime

  6. Once all shopping done, person hit checkout (leades to checkout.php) which displays all basket items, with a "purchase" buttong at the bottom, which once hit will process all orders (no money involved, just detuct qty ordered from database).

using the example above, i know and understand:

  1. how to display data on both pages.

  2. checkout for specific products, right now next to each item i have a "purchase" butoon. if i hit the "purchase" button next to a specific item, it will actually query the database using the UPDATE statement and detuct whatever qty i selected for that item. I don't want this, instead i want it to be added to basket and processed when i hit "checkout" along with all other orders.

what i need to understand:

  1. when i hit "add to basket" next to a item, how to keep the item added with its qty and which type of products its (fruits or veg) in memory

  2. how to batch process all sets of fuit order and sets of veg orders

i know there will b seesion or seesions arrays involved, which i want u to explain

where things are not obvious, please comment so i know whats happening

    mars16 -

    See this post for an explanation of the usual approach to shopping carts.

    Also, I'd say that having separate tables for fruits and vegetables is probably a bad idea, for a number of reasons:

    • You'll have to duplicate code for each category.

    • If you need to add a new category to the site, you'll have to write new code, rather than just updating the database.

    • If you need to change the way the site works, you'll have to change the existing code for each individual category.

    • It will make reporting and auditing against your product tables extremely annoying.

    • Lots of other reasons. Just trust me, eh? 🙂

    It'd be much better to have a single table named "products"; then, create another table named "categories", and add a column to the products table that indicates which category each product belongs to. Example:

    Contents of "categories" table:

    id   name
    1    Fruits
    2    Vegetables

    Contents of "products" table:

    id   name        category_id
    1    Banana      1
    2    Carrot      2
    3    Zucchini    2
    4    Grapes      1

    Then, to select all products from a given category, just do SELECT * FROM products WHERE category_id = whatever.

      the reason i said seprate tables because a project i have a project at hand now that has products with seprate field headings and don't make sense to group together in a table, like hotels and flights but for the sake for simplifing my question i said fruit and veg.

        ok i read the link you posted, its straight forward and i understand it. But i have two different types of products (flight and hotels), Do you still advice me to have one products tables?

        i was thinking keep them 2 tables and have 2 shopping carts tables (one for each), what You think?

          definitely not... redundancy in a DB isnt a good thing... just group them together and when you call things just do something like

          For Veggies:
          select * FROM products WHERE category='vegetable'

          For Fruits:
          select * FROM products WHERE category='fruit'

          any other way and you are making it way too complex and annoying... it may seem simpler now but its not

          also you dont want 2 php files... just one

            Write a Reply...