Storing data

Discussion in 'Programming' started by gazzieh, Apr 4, 2012.

to remove all ads.
  1. gazzieh

    gazzieh New Member

    Messages:
    33
    Okay, ignore my post about temporary tables; this was a red herring!

    I am trying to create something akin to a shopping cart. I want someone to click on Order on one page and this data be stored, allowing them to add more and more items until they finally complete the transaction.

    I could see this as an array with a structure or type definition, if I were coding in VB or similar; but would be concerned about having an expanding array (not knowing how many transactions it would need to be holding). I could set a limit (say, create an array of 20; knowing that they are unlikely to order 20 items) but this could lead to failure. Equally, does PHP allow for the use of structure definitions (formerly I knew these as types)?

    What would be a good way of dealing with this issue?

    Is the session_id unique; never to be repeated? Could I use this within a purchase history table in the database to uniquely identify the current user's requests. There is no log in requirement here (final purchase is through PayPal) so there is no other Unique ID system.

    There are some nice potentials from this latter approach but what would you suggest?
     
  2. leroy30

    leroy30 New Member

    Messages:
    485
    Hi gazzieh,

    You *could* store an array in session state. I don't know in PHP but in ASP.net you can have an array list that grows as your requirement grows.

    However if you store in the session and the user leaves the page then the shopping list is lost.

    If the user is a registered user then have a 'cart' table that stored the current shopping list.

    If there is no sign up necessary (as you mentioned) then simply store the shopping list in the users cookies. When it comes time to order then validate each item in the cookie against the database - i.e. don't take it for granted that the price and item in the client (user) cookie is valid. But if they match the current database items then proceed with the order.

    That would be how I'd do it.
     
  3. Edge

    Edge Member

    Messages:
    461
    Wow, lailagwb, can I just a big thankyou for that amazingly useful contribution.
     

Share This Page