SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help creating dynamic forms!

    I have spent the past month trying to teach myself PHP using Dreamweaver and MySQL. I have been fairly successful but have found I have huge holes in my basic knowledge. Can someone help with my question or reccommend a good book to help my learning curve.

    I am selling clothing on line and on my product page I want to offer drop down menus for size, color, etc. These change depending on the product chosen. How do I pull the forms dynamically from MySQL? Do I need to build a table that lists every option per product, i.e. if there are 4 sizes and 2 colors I need to list the item 8 times?? I have no problem creating the forms or running queries from MySQL, but I can' figure out how to do this.

    Any help is appreciated. If you want to see the site for an idea of what I trying please do. www.atthenet.co.uk

    Thanks!

  2. #2
    SitePoint Evangelist djdykes's Avatar
    Join Date
    Feb 2005
    Location
    Chester, Cheshire
    Posts
    565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use arrays.

    some code i've done recently looks like this...

    PHP Code:

    $settings 
    = array('stylesheet' => 'css2.css''title' => 'Tutorial Editor''path' => '../tutorials');
    //declare select exlement outside a loop
    echo "<form method='post' action=''><select>";

    loop through your array and generate select options
    foreach($settings as $key => $val){
     echo 
    "<option value=\"$key\">$val</option>";
    }
    // maybe have extra fields here outside the loop...
    echo "</select></form>"
    now this is a fairly static example but, easiest in my oppinion, you could pull this data from a DB but when it is the same for each item you're selling. there is no need to store it in a db. stick it in an array and just include the file containing the array. then if it changes edit the array file

    hope that helps

  3. #3
    Fully Sweet Car noddy's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Western Australia
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you should have a inventory of your products that has the sizes and colours available. could be the same table or separate up to you.

    Then your query can just be on your inventory fields and the quantity

  4. #4
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The problem I have is that some items such as 'sports bags' do not need a size but need color options. Then a lot of the clothing items have size but no color option, while other have color and size. I have only a single product_detail page that I pull everything in to, so I would like to also pull the option forms along with my other detail.

    This is why I was asking about a table that lists each item mulitplied by the number of option combinations....

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I forgot to say thanks for the feedback. I am away from my site's computer at the minute so cannot test out your array to see what it does for me. Will let you know as soon as I do.

  6. #6
    Fully Sweet Car noddy's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Western Australia
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you need to setup a one to many kind of relationship.

    You have a product which is a product ID and you are trying to reference a lot of different variables and tie it into one product.

    I think it would be much better to have a table with each variation in size colour etc as different product ids. Becase in the real world situation they are physically different product or items of clothing you are talking about.

    My comparison is its like having the same barcode for a L womens size red wollen jumper and also having the same barcode for the L womens size blue wollen or sheepskin jumper.

    I hope that makes sense.

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That makes complete sense, thanks! I was hoping I suppose not to have a table 400 odd products long to do this. but I suppose it will be used as my inventory tracking as well and keep things clearer.

    If I set up a one to many kind releationship and pull out my 8 options is it simply a matter of putting the string(s) into a form code?

  8. #8
    Fully Sweet Car noddy's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Western Australia
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah basically


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
  •