SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    form with multiple data

    in a database products with various attributes are stored, eg
    jersey in sizes Small, Medium, Large XLarge
    wallet in Black, Blue, Red, Yellow
    etc.

    when displaying a product those attributes will be shown + a field for entering the desired quantity for purchasing it:


    Code:
    Jersey
    
    Size     | Qty
    Small    | [0]
    Medium   | [0]
    Large    | [0]
    XLarge   | [0]
    or
    Code:
    Wallet
     
    Color    | Qty
    Black    | [0]
    Blue     | [0]
    Red      | [0]
    Yellow   | [0]
    as said, both attributes (eg size or color) and the quantity are produced dynamically from the database.
    Now if a user buys 2 Jerseys in Medium, ie types a 2 into the quantity input field of Medium and presses 'submit',
    how do i know that the quantity of 2 refers to the medium jersey?
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://www.php.net/manual/en/faq.htm...aq.html.arrays

    Code:
    <input name="items[Jersey][Small]">
    <input name="items[Jersey][Medium]">
    
    <input name="items[Wallet][Black]">
    <input name="items[Wallet][Blue]">
    PHP Code:
    print_r($_POST['items']); 
    However, if you give each item its own itemid, this wouldn't be neccesary at all. A blue wallet would have a different itemid than a black wallet. Then you can just use a single dimensional array like
    Code:
    <input name="items[123]">
    <input name="items[124]">
    
    <input name="items[555]">
    <input name="items[556]">


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
  •