Jump to content


This topic is now archived and is closed to further replies.


Subs associated to Items (Looping)

Recommended Posts

Ok, here is my scenario:

Customer chooses shirts from a combo box (multiple selection):
Shirt 1
Shirt 2
Shirt 3
Shirt 4
Shirt 5

When 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, LG
Shirt 2 => SM, MD, LG, 1X
Shirt 3 => One Size

Next, the customer checks the sizes they want from the available sizes. Say they select:
Shirt 1: SM, MD
Shirt 2: MD, 1X
Shirt 3: One Size

When 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, MD
Shirt 2 => MD, 1X
Shirt 3 => One Size

I'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, MD
Shirt 2 => SM, MD
Shirt 3 => SM, MD

Its not displaying the checked sizes for the correct shirt.

Can anyone help me out here?

Share this post

Link to post
Share on other sites
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">

$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>';

Share this post

Link to post
Share on other sites
Where are the sizes coming from. Database? or are you just typing them in?? Maybe a little more code would help.


Share this post

Link to post
Share on other sites
If your form with sizes for the selected products looks like this, where each size checkbox has

name = "size[product id][]"

<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">

The processing to show the sizes would be

if (isset($_POST['submit'])) {
foreach ($_POST['size'] as $id => $sizes)  {
echo "<br>$id ";
foreach ($sizes  as $sz) {
echo "$sz ";

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.