<?php
$variable = $_GET['Listing'];

$con = mysqli_connect('localhost', 'mayabeac_wine', '3]eGo-r(Scru',"mayabeac_WineList");
        if (mysqli_connect_errno()) {
            echo"
                Failed to connect to the MySQL DB:".mysqli_connect_error();
            }
           else{


}
 
mysqli_query($con, "SET NAMES 'utf8'");


 	
       echo "<b><span style='display: inline-block; text-align: left; width:100%; line-height: 200%; font-size: 150%'>".$variable."</span></b>";

     	$sql="SELECT * FROM Wines WHERE QtyInStock>0 AND (Category ='".$variable."' OR Category2 = '".$variable."' OR Category3 ='".$variable."') AND WineType != 'Glass' ORDER BY WinePrice";
      	$records1=mysqli_query($con, $sql);
      	
        echo "<table style='width: 100%'>";
        echo "<colgroup>";
        echo "<col span='1' style='width: 85%;'>";
        echo "<col span='1' style='width: 15%;'>";
        echo "</colgroup>";
        $wineCount = 0;
      	while($wines=mysqli_fetch_assoc($records1)){
        $wineCount=$wineCount+1;	          
          if($wines['WineVintage']==0){
          	
            $vintage=NULL;	
          }
          else{
          	$vintage=$wines['WineVintage'];
          }
            if($wines['QtyInStock'] < 3){  
          $lowStock = "* ";
          }
          else{
          $lowStock = "";
           }  

          if($wines['WineSize']<750 AND $wines['WineSize']!=0){
                $sizeinfo="&nbsp;(small bottle)";
          }
          else{
               $sizeinfo="";
          }
  if (wonderplugin_is_device('Windows,Mac,Linux,iPad')){
$singlePage="single-item/";
}
else{
$singlePage="singleitem-smallscreen/";
}
          

           $wineID="<b><a href='http://www.bistrowinelist.com/".$singlePage."?WineID=".$wines['ID']."&listType=byVarietal&listName=".$variable."&linkCount=1#wine".$wineCount."'>".$lowStock.$wines['WineName'].$sizeinfo."&emsp;".$vintage."</a></b>";


echo "<tr>"; 
echo "<td style='text-align: left; vertical-align: bottom; font-size: 1.25em; height: 80%; padding-top: 0px; padding-bottom: 0px; '>".$wineID."</td>";

                
                $winePrice="<b>$".$wines['WinePrice']."</b>";
                echo "<td style='font-size: 1.25em; text-align: right; vertical-align: bottom; height: 80%; padding-top: 0px; padding-bottom: 0px;'>".$winePrice."</td></tr>"; 
            
               $wineCountry=$wines['WineCountry'].">".$wines['WineRegion'];
                if(substr($wineCountry, strlen($wineCountry)-1,1)==">"){

                       $wineCountry=substr($wineCountry, 0, strlen($wineCountry)-1);
                }
 echo "<td style='text-align: left; vertical-align: bottom; font-size: 1em; height: 80%; padding-top: 0px; padding-bottom: 0px; '>".$wineCountry."</td>";

     
        	echo "<tr><td style='text-align: left; vertical-align: top; height: 80%; padding-top: 0px; padding-bottom: 1em; '>".$wines['WineVarietal']."</td></tr>";

        }
        echo "</table>";
      	echo "<br><font size='-1'>All prices are in Belize Dollars and include 12.5% GST (Sales Tax).&nbsp; BZ$2 = US$1<font>";
echo "<br><font size='-1'>* Limited Quantities Available<font>";