<?php include("../templates/header.php"); ?>
<?php include("check_admin.php"); ?>

<div class="panel panel-primary">
  <div class="panel-heading">
    <h3 class="panel-title">ข้อมูลการซื้อเลข</h3>
  </div>
  <div class="panel-body">

  <center><b>สรุปรายการตัวเลขที่มีในระบบ  ณ ตอนนี้ (ตัวเลข/จำนวน)</b></center><br>

  <?php

//==A==================================================================

  $sql1 = "select distinct num_buy from tb_number where num_buy between '0' and '49' and num_type='a' and num_clear='No' order by num_buy"; 
  $Query1 = mysqli_query($link,$sql1);
  $num_rows1 = mysqli_num_rows($Query1);

  $sql2 = "select distinct num_buy from tb_number where num_buy between '50' and '99' and num_type='a' and num_clear='No' order by num_buy"; 
  $Query2 = mysqli_query($link,$sql2);
  $num_rows2 = mysqli_num_rows($Query2);

  if($num_rows1 || $num_rows2){
  	echo "
    <table class='table table-bordered'>
    <thead>
      <tr class='success'>
        <th><center>ประเภทเลข 2 ตัว 0-49</th>
        <th><center>ประเภทเลข 2 ตัว 50-100</th>
      </tr>
    </thead>
    <tbody><tr><td>";


    echo "<table><tr><td>";

	  while($Result = mysqli_fetch_array($Query1)){

      $num_total = 0;

	  	$num_buy = $Result['num_buy'];
	  	$sum_sql = "select * from tb_number where num_buy='$num_buy' and num_type='a' and num_clear='No'"; 
	  	$sum_Query = mysqli_query($link,$sum_sql);
	  	$num_rows = mysqli_num_rows($sum_Query);

      $sum_Query1 = mysqli_query($link,$sum_sql);
      while($Result = mysqli_fetch_array($sum_Query1)){
      $num_one = $Result['num_one'];
      $num_two = $Result['num_two'];
      $num_total = $num_one+$num_two+$num_total;
      }

	  echo "$num_buy = $num_rows ยอดรวม $num_total<br>";

	  }

    echo "</td></tr></table></td><td>";
    echo "<table><tr><td>";

     while($Result = mysqli_fetch_array($Query2)){

      $num_total = 0;

      $num_buy = $Result['num_buy'];
      $sum_sql = "select * from tb_number where num_buy='$num_buy' and num_type='a' and num_clear='No'"; 
      $sum_Query = mysqli_query($link,$sum_sql);
      $num_rows = mysqli_num_rows($sum_Query);

      $sum_Query1 = mysqli_query($link,$sum_sql);
      while($Result = mysqli_fetch_array($sum_Query1)){
      $num_one = $Result['num_one'];
      $num_two = $Result['num_two'];
      $num_total = $num_one+$num_two+$num_total;
      }

    echo "$num_buy = $num_rows ยอดรวม $num_total<br>";

    }

    echo "</td></tr></table>";
    echo "</td></tr></tbody></table>";

  }
  else{
  	echo "<i><b>ประเภทเลข 2 ตัว</b></i> <font color='red'>ยังไม่มีรายการซื้อ</font><br>";
  }
  echo "<hr>";

//==B==================================================================
  
  $sql1 = "select distinct num_buy from tb_number where num_buy between '000' and '099' and num_type='b' and num_clear='No' order by num_buy"; 
  $Query1 = mysqli_query($link,$sql1);
  $num_rows1 = mysqli_num_rows($Query1);

  $sql2 = "select distinct num_buy from tb_number where num_buy between '100' and '199' and num_type='b' and num_clear='No' order by num_buy"; 
  $Query2 = mysqli_query($link,$sql2);
  $num_rows2 = mysqli_num_rows($Query2);

  $sql3 = "select distinct num_buy from tb_number where num_buy between '200' and '299' and num_type='b' and num_clear='No' order by num_buy"; 
  $Query3 = mysqli_query($link,$sql3);
  $num_rows3 = mysqli_num_rows($Query3);

  $sql4 = "select distinct num_buy from tb_number where num_buy between '300' and '399' and num_type='b' and num_clear='No' order by num_buy"; 
  $Query4 = mysqli_query($link,$sql4);
  $num_rows4 = mysqli_num_rows($Query4);

  $sql5 = "select distinct num_buy from tb_number where num_buy between '400' and '499' and num_type='b' and num_clear='No' order by num_buy"; 
  $Query5 = mysqli_query($link,$sql5);
  $num_rows5 = mysqli_num_rows($Query5);

  $sql6 = "select distinct num_buy from tb_number where num_buy between '500' and '599' and num_type='b' and num_clear='No' order by num_buy"; 
  $Query6 = mysqli_query($link,$sql6);
  $num_rows6 = mysqli_num_rows($Query6);

  $sql7 = "select distinct num_buy from tb_number where num_buy between '600' and '699' and num_type='b' and num_clear='No' order by num_buy"; 
  $Query7 = mysqli_query($link,$sql7);
  $num_rows7 = mysqli_num_rows($Query7);

  $sql8 = "select distinct num_buy from tb_number where num_buy between '700' and '799' and num_type='b' and num_clear='No' order by num_buy"; 
  $Query8 = mysqli_query($link,$sql8);
  $num_rows8 = mysqli_num_rows($Query8);

  $sql9 = "select distinct num_buy from tb_number where num_buy between '800' and '899' and num_type='b' and num_clear='No' order by num_buy"; 
  $Query9 = mysqli_query($link,$sql9);
  $num_rows9 = mysqli_num_rows($Query9);

  $sql10 = "select distinct num_buy from tb_number where num_buy between '900' and '999' and num_type='b' and num_clear='No' order by num_buy"; 
  $Query10 = mysqli_query($link,$sql10);
  $num_rows10 = mysqli_num_rows($Query10);

  if($num_rows1 || $num_rows2 || $num_rows3 || $num_rows4 || $num_rows5 || $num_rows6 || $num_rows7 || $num_rows8 || $num_rows9 || $num_rows10){

    echo "
    <table class='table table-bordered'>
    <thead>
      <tr class='success'>
        <th><center>ประเภทเลข 3 ตัว 0-099</th>
        <th><center>ประเภทเลข 3 ตัว 100-199</th>
        <th><center>ประเภทเลข 3 ตัว 200-299</th>
        <th><center>ประเภทเลข 3 ตัว 300-399</th>
        <th><center>ประเภทเลข 3 ตัว 400-499</th>
      </tr>
    </thead>
    <tbody><tr><td>";


    if($num_rows1 || $num_rows2 || $num_rows3 || $num_rows4 || $num_rows5){

      //=============================================== 1

      echo "<table><tr><td>";
      while($Result = mysqli_fetch_array($Query1)){
      $num_total = 0;

      $num_buy = $Result['num_buy'];
      $sum_sql = "select * from tb_number where num_buy='$num_buy' and num_type='b' and num_clear='No'"; 
      $sum_Query = mysqli_query($link,$sum_sql);
      $num_rows = mysqli_num_rows($sum_Query);

      $sum_Query1 = mysqli_query($link,$sum_sql);
      while($Result = mysqli_fetch_array($sum_Query1)){
      $num_one = $Result['num_one'];
      $num_two = $Result['num_two'];
      $num_total = $num_one+$num_two+$num_total;
      }

      echo "$num_buy = $num_rows ยอดรวม $num_total<br>";
      
      }
      echo "</td></tr></table></td>";

      //=============================================== 2

      echo "<td><table><tr><td>";
      while($Result = mysqli_fetch_array($Query2)){
      $num_total = 0;

      $num_buy = $Result['num_buy'];
      $sum_sql = "select * from tb_number where num_buy='$num_buy' and num_type='b' and num_clear='No'"; 
      $sum_Query = mysqli_query($link,$sum_sql);
      $num_rows = mysqli_num_rows($sum_Query);

      $sum_Query1 = mysqli_query($link,$sum_sql);
      while($Result = mysqli_fetch_array($sum_Query1)){
      $num_one = $Result['num_one'];
      $num_two = $Result['num_two'];
      $num_total = $num_one+$num_two+$num_total;
      }

      echo "$num_buy = $num_rows ยอดรวม $num_total<br>";

      }
      echo "</td></tr></table></td>";

      //=============================================== 3

      echo "<td><table><tr><td>";
      while($Result = mysqli_fetch_array($Query3)){
      $num_total = 0;

      $num_buy = $Result['num_buy'];
      $sum_sql = "select * from tb_number where num_buy='$num_buy' and num_type='b' and num_clear='No'"; 
      $sum_Query = mysqli_query($link,$sum_sql);
      $num_rows = mysqli_num_rows($sum_Query);

      $sum_Query1 = mysqli_query($link,$sum_sql);
      while($Result = mysqli_fetch_array($sum_Query1)){
      $num_one = $Result['num_one'];
      $num_two = $Result['num_two'];
      $num_total = $num_one+$num_two+$num_total;
      }

      echo "$num_buy = $num_rows ยอดรวม $num_total<br>";

      }
      echo "</td></tr></table></td>";

      //=============================================== 4

      echo "<td><table><tr><td>";
      while($Result = mysqli_fetch_array($Query4)){
      $num_total = 0;

      $num_buy = $Result['num_buy'];
      $sum_sql = "select * from tb_number where num_buy='$num_buy' and num_type='b' and num_clear='No'"; 
      $sum_Query = mysqli_query($link,$sum_sql);
      $num_rows = mysqli_num_rows($sum_Query);

      $sum_Query1 = mysqli_query($link,$sum_sql);
      while($Result = mysqli_fetch_array($sum_Query1)){
      $num_one = $Result['num_one'];
      $num_two = $Result['num_two'];
      $num_total = $num_one+$num_two+$num_total;
      }

      echo "$num_buy = $num_rows ยอดรวม $num_total<br>";

      }
      echo "</td></tr></table></td>";

      //=============================================== 5

      echo "<td><table><tr><td>";
      while($Result = mysqli_fetch_array($Query5)){
      $num_total = 0;

      $num_buy = $Result['num_buy'];
      $sum_sql = "select * from tb_number where num_buy='$num_buy' and num_type='b' and num_clear='No'"; 
      $sum_Query = mysqli_query($link,$sum_sql);
      $num_rows = mysqli_num_rows($sum_Query);

      $sum_Query1 = mysqli_query($link,$sum_sql);
      while($Result = mysqli_fetch_array($sum_Query1)){
      $num_one = $Result['num_one'];
      $num_two = $Result['num_two'];
      $num_total = $num_one+$num_two+$num_total;
      }

      echo "$num_buy = $num_rows ยอดรวม $num_total<br>";

      }
      echo "</td></tr></table></td>";

      //===============================================

    }

    echo "</td><tr class='success'>
        <th><center>ประเภทเลข 3 ตัว 500-599</th>
        <th><center>ประเภทเลข 3 ตัว 600-699</th>
        <th><center>ประเภทเลข 3 ตัว 700-799</th>
        <th><center>ประเภทเลข 3 ตัว 800-899</th>
        <th><center>ประเภทเลข 3 ตัว 900-999</th>
      </tr><td>";


    if($num_rows6 || $num_rows7 || $num_rows8 || $num_rows9 || $num_rows10){

      //=============================================== 6

      echo "<table><tr><td>";
      while($Result = mysqli_fetch_array($Query6)){
      $num_total = 0;

      $num_buy = $Result['num_buy'];
      $sum_sql = "select * from tb_number where num_buy='$num_buy' and num_type='b' and num_clear='No'"; 
      $sum_Query = mysqli_query($link,$sum_sql);
      $num_rows = mysqli_num_rows($sum_Query);

      $sum_Query1 = mysqli_query($link,$sum_sql);
      while($Result = mysqli_fetch_array($sum_Query1)){
      $num_one = $Result['num_one'];
      $num_two = $Result['num_two'];
      $num_total = $num_one+$num_two+$num_total;
      }

      echo "$num_buy = $num_rows ยอดรวม $num_total<br>";

      }
      echo "</td></tr></table></td>";

      //=============================================== 7

      echo "<td><table><tr><td>";
      while($Result = mysqli_fetch_array($Query7)){
      $num_total = 0;

      $num_buy = $Result['num_buy'];
      $sum_sql = "select * from tb_number where num_buy='$num_buy' and num_type='b' and num_clear='No'"; 
      $sum_Query = mysqli_query($link,$sum_sql);
      $num_rows = mysqli_num_rows($sum_Query);

      $sum_Query1 = mysqli_query($link,$sum_sql);
      while($Result = mysqli_fetch_array($sum_Query1)){
      $num_one = $Result['num_one'];
      $num_two = $Result['num_two'];
      $num_total = $num_one+$num_two+$num_total;
      }

      echo "$num_buy = $num_rows ยอดรวม $num_total<br>";

      }
      echo "</td></tr></table></td>";

      //=============================================== 8

      echo "<td><table><tr><td>";
      while($Result = mysqli_fetch_array($Query8)){
      $num_total = 0;

      $num_buy = $Result['num_buy'];
      $sum_sql = "select * from tb_number where num_buy='$num_buy' and num_type='b' and num_clear='No'"; 
      $sum_Query = mysqli_query($link,$sum_sql);
      $num_rows = mysqli_num_rows($sum_Query);

      $sum_Query1 = mysqli_query($link,$sum_sql);
      while($Result = mysqli_fetch_array($sum_Query1)){
      $num_one = $Result['num_one'];
      $num_two = $Result['num_two'];
      $num_total = $num_one+$num_two+$num_total;
      }

      echo "$num_buy = $num_rows ยอดรวม $num_total<br>";

      }
      echo "</td></tr></table></td>";

      //=============================================== 9

      echo "<td><table><tr><td>";
      while($Result = mysqli_fetch_array($Query9)){
      $num_total = 0;

      $num_buy = $Result['num_buy'];
      $sum_sql = "select * from tb_number where num_buy='$num_buy' and num_type='b' and num_clear='No'"; 
      $sum_Query = mysqli_query($link,$sum_sql);
      $num_rows = mysqli_num_rows($sum_Query);

      $sum_Query1 = mysqli_query($link,$sum_sql);
      while($Result = mysqli_fetch_array($sum_Query1)){
      $num_one = $Result['num_one'];
      $num_two = $Result['num_two'];
      $num_total = $num_one+$num_two+$num_total;
      }

      echo "$num_buy = $num_rows ยอดรวม $num_total<br>";

      }
      echo "</td></tr></table></td>";

      //=============================================== 10

      echo "<td><table><tr><td>";
      while($Result = mysqli_fetch_array($Query10)){
      $num_total = 0;

      $num_buy = $Result['num_buy'];
      $sum_sql = "select * from tb_number where num_buy='$num_buy' and num_type='b' and num_clear='No'"; 
      $sum_Query = mysqli_query($link,$sum_sql);
      $num_rows = mysqli_num_rows($sum_Query);

      $sum_Query1 = mysqli_query($link,$sum_sql);
      while($Result = mysqli_fetch_array($sum_Query1)){
      $num_one = $Result['num_one'];
      $num_two = $Result['num_two'];
      $num_total = $num_one+$num_two+$num_total;
      }

      echo "$num_buy = $num_rows ยอดรวม $num_total<br>";

      }
      echo "</td></tr></table></td>";

      //===============================================

    }

    echo "</td></tr></tbody></table>";

  }
  else{
  	echo "<i><b>ประเภทเลข 3 ตัว</b></i> <font color='red'>ยังไม่มีรายการซื้อ</font><br>";
  }
  echo "<hr>";

//==C==================================================================
  
  $sql = "select distinct num_buy from tb_number where num_type='c' and num_clear='No' order by num_buy"; 
  $Query = mysqli_query($link,$sql);
  $num_rows = mysqli_num_rows($Query);

  if($num_rows){

    echo "
    <table class='table table-bordered'>
    <thead>
      <tr class='success'>
        <th><center>ประเภทเลขวิ่ง</th>
      </tr>
    </thead>
    <tbody><tr><td>";

	  while($Result = mysqli_fetch_array($Query)){

      $num_total = 0;

	  	$num_buy = $Result['num_buy'];
	  	$sum_sql = "select * from tb_number where num_buy='$num_buy' and num_type='c' and num_clear='No'"; 
	  	$sum_Query = mysqli_query($link,$sum_sql);
	  	$num_rows = mysqli_num_rows($sum_Query);

      $sum_Query1 = mysqli_query($link,$sum_sql);
      while($Result = mysqli_fetch_array($sum_Query1)){
      $num_one = $Result['num_one'];
      $num_two = $Result['num_two'];
      $num_total = $num_one+$num_two+$num_total;
      }

    echo "$num_buy = $num_rows ยอดรวม $num_total<br>";

	  }

    echo "</td></tr></tbody></table>";

  }
  else{
  	echo "<i><b>ประเภทเลขวิ่ง</b></i> <font color='red'>ยังไม่มีรายการซื้อ</font><br>";
  }
  echo "<hr>";

//==D==================================================================
  

  $sql1 = "select distinct num_buy from tb_number where num_buy between '0' and '49' and num_type='d' and num_clear='No' order by num_buy"; 
  $Query1 = mysqli_query($link,$sql1);
  $num_rows1 = mysqli_num_rows($Query1);

  $sql2 = "select distinct num_buy from tb_number where num_buy between '50' and '99' and num_type='d' and num_clear='No' order by num_buy"; 
  $Query2 = mysqli_query($link,$sql2);
  $num_rows2 = mysqli_num_rows($Query2);

  if($num_rows1 || $num_rows2){
    echo "
    <table class='table table-bordered'>
    <thead>
      <tr class='success'>
        <th><center>ประเภทเลขใบ 2 ตัว 0-49</th>
        <th><center>ประเภทเลขใบ 2 ตัว 50-100</th>
      </tr>
    </thead>
    <tbody><tr><td>";


    echo "<table><tr><td>";

    while($Result = mysqli_fetch_array($Query1)){

      $num_total = 0;

      $num_buy = $Result['num_buy'];
      $sum_sql = "select * from tb_number where num_buy='$num_buy' and num_type='d' and num_clear='No'"; 
      $sum_Query = mysqli_query($link,$sum_sql);
      $num_rows = mysqli_num_rows($sum_Query);

      $sum_Query1 = mysqli_query($link,$sum_sql);
      while($Result = mysqli_fetch_array($sum_Query1)){
      $num_one = $Result['num_one'];
      $num_two = $Result['num_two'];
      $num_total = $num_one+$num_two+$num_total;
      }

    echo "$num_buy = $num_rows ยอดรวม $num_total ใบ<br>";

    }

    echo "</td></tr></table></td><td>";
    echo "<table><tr><td>";

     while($Result = mysqli_fetch_array($Query2)){

      $num_total = 0;

      $num_buy = $Result['num_buy'];
      $sum_sql = "select * from tb_number where num_buy='$num_buy' and num_type='d' and num_clear='No'"; 
      $sum_Query = mysqli_query($link,$sum_sql);
      $num_rows = mysqli_num_rows($sum_Query);

      $sum_Query1 = mysqli_query($link,$sum_sql);
      while($Result = mysqli_fetch_array($sum_Query1)){
      $num_one = $Result['num_one'];
      $num_two = $Result['num_two'];
      $num_total = $num_one+$num_two+$num_total;
      }

    echo "$num_buy = $num_rows ยอดรวม $num_total ใบ<br>";

    }

    echo "</td></tr></table>";
    echo "</td></tr></tbody></table>";

  }
  else{
  	echo "<i><b>ประเภทเลขใบ</b></i> <font color='red'>ยังไม่มีรายการซื้อ</font><br>";
  }

  ?>
  

  </div>
</div>

<?php include("../templates/footer.php"); ?>