I've got a database having a load of items and i'm attempting to output them. A few of the items have a similar itemid but different dimensions.

The issue i am getting gets the items with similar itemid right into a choose list. I'm able to output the items normally however i want tro group the same product inside a choose list.

This is a connect to my website having a hard coded product list http://operationbraveheart.org.uk/jcart/.

here is a hyperlink towards the creation of my code http://operationbraveheart.org.uk/jcart/testshop.php

What's happening is the fact that rather than a lot of various forms for every product being displayed, i recieve one form having a massive empty choose list.

I wish to make a move similar but rather than hard coding, i wish to loop thought the database, if there's just one item with this itemid, it is a normal form, if there's several with similar itemid, it is going inside a choose list.

Here's my code that shoudl output the items

echo "<table border='0' id='gallery'>";

    while ($row = $result->fetchrow()) { 
        $superitem[$row['itemid']][] = $row;
    }

    foreach($superitem AS $subitem) {
        list($prodid,$item,$description,$price) = $subitem[0];

        if ($count % NUMCOLS == 0) echo "<tr>";  # new row
        echo '<td>';

        //Your normal code up until the select box...
        echo '<form method="post" action="" class="jcart">
                <fieldset>
                    <input type="hidden" name="jcartToken" value="'.$_SESSION['jcartToken'].'" />
                    <input type="hidden" name="my-item-id" value="2" />
                    <input type="hidden" name="my-item-price" value="19.50" />
                    <input type="hidden" name="my-item-url" value="http://yahoo.com" />';

        if(count($subitem) > 1) {
            echo '<li><select name="my-item-name" id="foo">';
            foreach($subitem AS $subsubitem) {
                echo "<option value='".$subsubitem['size']."'>".$subsubitem['size']."</option>";
            }
            echo "</select></li>";
        }
        else {
            echo '<input type="hidden" name="my-item-name" value="'.$item.'" />'; 
        }
        echo'<li>Price: $<span class="price">10.00</span></li>
                    <li>
                        <label>Qty: <input type="text" name="my-item-qty" value="1" size="3" /></label>
                    </li>
                </ul>

                <input type="submit" name="my-add-button" value="add to cart" class="button" />
            </fieldset>
        </form>';

        echo '</td>';
        $count++;
        $counter++;

        if ($count % NUMCOLS == 0) echo "</tr>\n";  # end row
    }
    if ($count % NUMCOLS != 0) {
       while ($count++ % NUMCOLS) echo "<td>&nbsp;</td>";
       echo "</tr>";
    }
    echo "</table>";

Here's my table structure and example data

  CREATE TABLE `shop` (
  `prodid` int(2) NOT NULL auto_increment,
  `itemid` int(2) NOT NULL default '0',
  `item` varchar(50) NOT NULL default '',
  `size` char(2) NOT NULL default '',
  `description` text NOT NULL,
  `image` varchar(50) NOT NULL default '',
  `price` float NOT NULL default '0',
  PRIMARY KEY  (`prodid`)
) 

INSERT INTO `shop` VALUES (1, 1, 'Key Ring', '', 'Key Ring: This can be personalised', '', 2);
INSERT INTO `shop` VALUES (2, 2, 'Tableware', '', 'Tableware: Coasters and Table Mats', '', 3);
INSERT INTO `shop` VALUES (3, 3, 'Braveheart Bear', '', '7" Braveheart Bear (choice of T-Shrt)', '', 9.99);
INSERT INTO `shop` VALUES (4, 4, 'Bravehart Bear', '', '9" Braveheart Bear (choice of T-Shirt)', '', 11.99);
INSERT INTO `shop` VALUES (5, 5, 'Wristband', '', 'Operation Braveheart wristband', '', 2);
INSERT INTO `shop` VALUES (6, 6, 'Mug', '', 'Standard mug', '', 7.99);
INSERT INTO `shop` VALUES (7, 7, 'A5 jotter', '', 'Various designs', '', 0.75);
INSERT INTO `shop` VALUES (8, 8, 'Operation Braveheart T-Shirt', 'S', 'Operation Braveheart T-Shirt.  All size in army green.', '', 6.99);
INSERT INTO `shop` VALUES (9, 8, 'Operation Braveheart T-Shirt', 'M', 'Operation Braveheart T-Shirt. All size in army green.', '', 7.99);
INSERT INTO `shop` VALUES (10, 8, 'Operation Braveheart T-Shirt', 'L', 'Operation Braveheart T-Shirt. All size in army green.', '', 8.99);
INSERT INTO `shop` VALUES (11, 8, 'Operation Braveheart T-Shirt', 'XL', 'Operation Braveheart T-Shirt. All size in army green.', '', 9.99);

I have now added print_r($superitem) and database structre/data