gabe8496 Posted August 18, 2006 Share Posted August 18, 2006 Ok, here is my scenario::FORM:Customer chooses shirts from a combo box (multiple selection):Shirt 1Shirt 2Shirt 3Shirt 4Shirt 5When user submits, it will display the shirts selected plus the subs (Sizes) associated to the item (with checkbox next to sub):Shirt 1 => SM, MD, LGShirt 2 => SM, MD, LG, 1XShirt 3 => One SizeNext, the customer checks the sizes they want from the available sizes. Say they select:Shirt 1: SM, MDShirt 2: MD, 1XShirt 3: One SizeWhen they hit submit, it will take them to a final page, displaying the shirt they chose plus the sizes they checked right next to the shirt.Shirt 1 => SM, MDShirt 2 => MD, 1XShirt 3 => One SizeI've created the loop that works good for displaying the shirts but it also displays the same subs for all shirts like so:Shirt 1 => SM, MDShirt 2 => SM, MDShirt 3 => SM, MDIts not displaying the checked sizes for the correct shirt.Can anyone help me out here? Quote Link to comment Share on other sites More sharing options...
gabe8496 Posted August 18, 2006 Author Share Posted August 18, 2006 Here is a snippet of the code were running:$_POST['item'] & $_POST['sub'] are setup as arrays on the previous page, because the checkbox for the subs are like so:<input type="checkbox" name="sub[]" value="SM"> [code]$item = $_POST['item'];$sub = $_POST['sub'];$item_array = count($item);$sub_array = count($sub);for ($x=0; $x<$item_array; $x++){echo ''.$item[$x].''; for ($i=0; $i<$sub_array; $i++) { echo ''.$sub[$i].''; } echo '<br>';}[/code] Quote Link to comment Share on other sites More sharing options...
craygo Posted August 18, 2006 Share Posted August 18, 2006 Where are the sizes coming from. Database? or are you just typing them in?? Maybe a little more code would help.Ray Quote Link to comment Share on other sites More sharing options...
Barand Posted August 18, 2006 Share Posted August 18, 2006 If your form with sizes for the selected products looks like this, where each size checkbox has name = "size[product id][]"[code]<FORM method='post'> Shirt 1 <input type="checkbox" name="size[1][]" value="SM">SM <input type="checkbox" name="size[1][]" value="MD">MD <input type="checkbox" name="size[1][]" value="LG">LG <BR> Shirt 2 <input type="checkbox" name="size[2][]" value="SM">SM <input type="checkbox" name="size[2][]" value="MD">MD <input type="checkbox" name="size[2][]" value="LG">LG <input type="checkbox" name="size[2][]" value="1X">1X <BR> Shirt 3 <input type="checkbox" name="size[3][]" value="1X">One Size <BR><input type="submit" name="submit" value="Submit"></FORM>[/code]The processing to show the sizes would be[code]<?php if (isset($_POST['submit'])) { foreach ($_POST['size'] as $id => $sizes) { echo "<br>$id "; foreach ($sizes as $sz) { echo "$sz "; } }}?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.