<?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==================================================================

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

  if($num_rows){
  	echo "<i><b>ประเภทเลข 2 ตัว</b></i><br>";

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

	  	$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);

	  echo "$num_buy = $num_rows<br>";

	  }

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

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

  if($num_rows){
  	echo "<i><b>ประเภทเลข 3 ตัว</b></i><br>";

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

	  	$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);

	  echo "$num_buy = $num_rows<br>";

	  }

  }
  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 "<i><b>ประเภทเลขวิ่ง</b></i><br>";

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

	  	$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);

	  echo "$num_buy = $num_rows<br>";

	  }

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

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

  if($num_rows){
  	echo "<i><b>ประเภทเลขใบ</b></i><br>";

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

	  	$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);

	  echo "$num_buy = $num_rows<br>";

	  }

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

  ?>
  

  </div>
</div>

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