<?php

     $qry="Select max(categoryKey) as categoryKey from couponItem where couponCode='" . $nt[code] . "'";
     $rslt=mysql_query($qry);
     while($cn=mysql_fetch_array($rslt)){
       $highestnum=$cn[categoryKey];
       $highestnum = $highestnum +2;
     }
     mysql_close;
        $count=1;
        $linebreak=1;
        while ($count <$highestnum) {
          if($linebreak>2){
            echo '<tr>';
            $linebreak =1;
          }
        $listname="Item#". $count;
        echo'<td valign="top" width=50%><table cellpadding=15 width=100%><td valign="top"><b><u>' . $listname . '</u></b><br>';

           $selectname = "couponitem" . $count ;
           echo'<div align="center"><Select name="' . $selectname . '"><option value="">---Add Choice---</option>';
           $catquery="Select CategoryName, RecordKey from menuCategory where CategoryName <>'Pizza Sauce' AND CategoryName <>'Pizza Toppings' AND
           CategoryName <>'Pizza Crust' AND CategoryName <>'Fixings' AND CategoryName <>'Options' order by orderNum";
            		$cqrt=mysql_query($catquery);          // query executed
                while($cqnt=mysql_fetch_array($cqrt)){
                     echo '<option value="">' . $cqnt[CategoryName] . '</option>';
                     $cpquery="Select itemKey, itemName from menuItem where categoryKey =". $cqnt[RecordKey];
                     $cprt=mysql_query($cpquery);          // query executed
                while($cpnt=mysql_fetch_array($cprt)){
                     echo '<option value=' . $cpnt[itemKey] . '>---' . $cpnt[itemName] . '</option>';
                }
                mysql_close;  //close item list loop within category
                     
                }
                mysql_close;   //close category list loop
             echo '</select></div>';
             $cpnitems="Select itemName, itemKey from menuItem where itemKey in(select itemNumber as itemKey from couponItem where categoryKey=" . $count . " AND couponCode='" . $nt[code] . "')";
        $ci=mysql_query($cpnitems);
         echo '<div align="left">' ;
        while($cn=mysql_fetch_array($ci)){
          //get selected size if any
          $sizeqry = "Select size from couponItem where itemNumber='" . $cn[itemKey] . "' AND categoryKey ='" .  $count . "' AND couponCode ='" . $nt[code] . "'";
          $sq=mysql_query($sizeqry);
          while($sn=mysql_fetch_array($sq)){
          $size=$sn[size];
        }
        mysql_close;
          echo $cn[itemName] . ' - ' .$size . ' <a href="' . $_SERVER['PHP_SELF'] . '?a=delitem&key='.$cn[itemKey]  . '&list='. $count .'&coupon=' . $nt[code] . '#' . $nt[couponNumber].'" title="remove"><font color="red" size=2>(x)</font></a><br>';
          //get available sizes to pick from for this item
          $sizeqry ="Select size from itemSize where itemKey =".$cn[itemKey] . " order by price DESC";
          $sq=mysql_query($sizeqry);
          echo'<div align="right">';
          while($sn=mysql_fetch_array($sq)){
          $size=$sn[size];
          echo '<a href="' . $_SERVER['PHP_SELF'] . '?a=size&couponkey='.$editcoupon  . '&key='.$cn[itemKey]  . '&list='. $count .'&coupon=' . $nt[code] . '&size='.$size . '#' . $nt[couponNumber].'" title="select size"><font color="blue" size=1><i>' . $size . '</a> - </i></font>';

        }
        if(!empty($size)){echo '<br>';}
        echo'</div>';
        mysql_close;
                  }
            echo '</div></table>';

         $count = $count + 1;
         $linebreak = $linebreak + 1;
         }
                

                
                
//include('publish.php');
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                
                ?>
                