SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Array Question

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Location
    Seattle, WA
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Array Question

    I'm trying to develop an order form that will list several products with a corresponding "Quantity Desired" text box next to each item and that will have a "Place Order" submit button at the bottom of the form. The idea is the customer will enter a quantity for each of the products desired and then place the order with one click.

    So far, I've been able to populate my order form with products by using a "SELECT" statement from my products table and a "mysql_fetch-array" query with a "while loop". No problem so far.

    Assuming the customer orders several items by entering several numbers in the "Quantity Desired" column and then by clicking on the "Place Order" button, an array should be generated (I hope) with the variables of: product id, description, price and quantity desired.

    What I want to do next is to INSERT this array into a "order_details" table, calculate the total price of the order, and then present all this as the contents of a typical shopping cart.

    I'm having difficulty figuring out how to INSERT the selected products array into the "order_details" table. Could someone please help me with this?

  2. #2
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IF your order_details table, has a separate entry for each order, which I assume it would, then you need to split up your array(s) and for each element in them insert the values into the database appropriately.
    Oh no! the coots are eating my nodes!

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2001
    Location
    Seattle, WA
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    timnz, I'm not exactly sure of what you're suggesting. Could you please elaborate?

    What I'll have after the customer selects several products is something like this:

    user_id, product id, description, price and quantity (for first item selected)
    user_id, product id, description, price and quantity (for second item selected)
    user_id, product id, description, price and quantity (for third item selected)
    etc. ...

    I'll also want to eliminate those items where the customer does not select the item by placing an integer great than zero in the "quantity desired" text box.

    Anyone else have a suggestion?

    SeattleDan

  4. #4
    Node mutilating coot timnz's Avatar
    Join Date
    Feb 2001
    Location
    New Zealand
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If this data is in a single array:
    user_id, product id, description, price and quantity (for first item selected)
    user_id, product id, description, price and quantity (for second item selected)
    user_id, product id, description, price and quantity (for third item selected)

    Then, say that array is called $orders,
    it would be something like:

    PHP Code:
    foreach ($orders as $value) {
    $user $value[0];
    $product $value[1];
    $description $value[2];
    $price $value[3];
    $quantity $value[4];
    $query mysql_query("INSERT INTO tablename....");

    Oh no! the coots are eating my nodes!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •