mysql_connect('localhost', 'root', 'admin'); 
mysql_query("SET NAMES 'utf8'");
mysql_select_db('WineList'); 
$sql="SELECT DISTINCT Category FROM Wines WHERE QtyInStock > 0 AND WineType = 'Red' ORDER BY Category";
 
$records = mysql_query($sql); 

$linecount = 1;
$reds = array();
$whites = array();
$redCount=0;
$whiteCount=0;

while($wine=mysql_fetch_assoc($records)){

          $redCount = $redCount + 1;
          $reds[$redCount] = $wine['Category'];
         //  echo $reds[$redCount];
}

$sql="SELECT DISTINCT Category FROM Wines WHERE QtyInStock > 0 AND WineType = 'White' ORDER BY Category";
 
$records = mysql_query($sql); 

while($wine=mysql_fetch_assoc($records)){

          $whiteCount = $whiteCount + 1;
          $whites[$whiteCount] = $wine['Category'];
         //  echo $whites[$whiteCount];
}

if($whiteCount > $redCount){
   $listItems = $whiteCount;
}
else{
   $listItems = $redCount;
}

echo "<TABLE BORDER=0 WIDTH=100% >";
echo "<tr><td><b>Whites</b></td><td><b>Reds</b></td></tr>";

      for($x = 1; $x <= $listItems; $x++){
             echo "<tr>";
             if($x <= $redCount){
            
                   $redstr = "<td><a href='http://192.168.104.254/wordpress/byVarietal/?Listing=".$reds[$x]."'>".$reds[$x]."</a></td>";
             }
             else{
              $redstr = "<td></td>";
             }
             
             if($x <= $whiteCount){
            
                   $whitestr = "<td><a href='http://192.168.104.254/wordpress/byVarietal/?Listing=".$whites[$x]."'>".$whites[$x]."</a></td>";
             }
             else{
              $whitestr = "<td></td>";
             }
            
             echo $whitestr;
             echo $redstr;
             echo "<tr>";
             

      }

echo "</TABLE>";