<div class="panel panel-primary">
  <div class="panel-heading">
    <h3 class="panel-title">ตารางรวม เลขวิ่ง</h3>
  </div>
  <div class="panel-body">

  <table class="table table-bordered">
    <thead>
      <tr>
        <th><center>ลำดับ</th>
        <th><center>เลขวิ่ง</th>
        <th><center>ราคาวิ่งบน</th>
        <th><center>ราคาวิ่งล่าง</th>
        <th><center>ยอดซื้อ</th>
        <th><center>ส่วนลด(ค่าคอม)</th>
        <th><center>ผลรางวัล</th>
        <th><center>คิดเงิน</th>
      </tr>
    </thead>
    <tbody>

	<?php

  // ตารางรวมเลข 2 ตัว

 	$sql = "select * from tb_number where acc_id='$session_id' and num_type='c' and num_clear='No'"; 
 	$Query = mysqli_query($link,$sql);
		
	$count = 0;
  $buysum = 0;
  $per_com = 0;
  $per_sum = 0;

  if($def_info == 'On'){
  $sum_n2 = 0;
  }
  else{
    $sum_n2 = "รอผล";
  }

	while($Result = mysqli_fetch_array($Query)){
	$num_id = $Result['num_id'];
	$num_buy = $Result['num_buy'];
	$num_one = $Result['num_one'];
	$num_two = $Result['num_two'];
	$num_created = $Result['num_created'];

  $buysum = $buysum+$num_one+$num_two;

  $n1 = "รอผล";
  $n2 = "รอผล";

  if($num_one != 0){

  $count = $count+1;
  $per_com = ($num_one*$acc_com5)/100;
  $per_sum = $per_sum+$per_com;

  if($def_info == 'On'){
    
    if($e1 == $num_buy || $e2 == $num_buy || $e3 == $num_buy){
      $n1 = "ถูกรางวัล";
      $n2 = ($num_one*$rate5)+(($num_one*$acc_com5)/100)-$num_one;
      $sum_n2 = $n2+$sum_n2;
      $n2 = number_format($n2);
      $n2 = "<font color='green'>$n2</font>";

    }
    else{
      $n1 = "ไม่ถูกรางวัล";
      $n2 = -($num_one-(($num_one*$acc_com5)/100));
      $sum_n2 = $n2+$sum_n2;
      $n2 = number_format($n2);
      $n2 = "<font color='red'>$n2</font>";
    }

  }
  else{

  }

    echo"<tr>
        <td align='center'>$count</td>
        <td align='center'>$num_buy</td>
        <td align='center'>$num_one</td>
        <td align='center'>-</td>
        <td align='center'>$num_one</td>
        <td align='center'>$per_com</td>
        <td align='center'>$n1</td>
        <td align='center'>$n2</td>
      </tr>";

  }

  if($num_two != 0){

  $count = $count+1;
  $per_com = ($num_two*$acc_com5)/100;
  $per_sum = $per_sum+$per_com;

  if($def_info == 'On'){
    
    if($e5 == $num_buy || $e6 == $num_buy){
      $n1 = "ถูกรางวัล";
      $n2 = ($num_two*$rate6)+(($num_two*$acc_com5)/100)-$num_two;
      $sum_n2 = $n2+$sum_n2;
      $n2 = number_format($n2);
      $n2 = "<font color='green'>$n2</font>";

    }
    else{
      $n1 = "ไม่ถูกรางวัล";
      $n2 = -($num_two-(($num_two*$acc_com5)/100));
      $sum_n2 = $n2+$sum_n2;
      $n2 = number_format($n2);
      $n2 = "<font color='red'>$n2</font>";
    }

  }

    echo"<tr>
        <td align='center'>$count</td>
        <td align='center'>$num_buy</td>
        <td align='center'>-</td>
        <td align='center'>$num_two</td>
        <td align='center'>$num_two</td>
        <td align='center'>$per_com</td>
        <td align='center'>$n1</td>
        <td align='center'>$n2</td>
      </tr>";

  }

	}

  //$per_sum = number_format($per_sum);

  if($def_info == 'On'){

  $num3 = $sum_n2;
  $sum_n2 = number_format($sum_n2);

  }


  echo"<tr>
        <td align='center'></td>
        <td align='center'></td>
        <td align='center'></td>
        <td align='center'><b>ยอดรวม</b></td>
        <td align='center'><b>$buysum</b></td>
        <td align='center'><b>$per_sum</b></td>
        <td align='center'><b>สรุปยอดรวม</b></td>
        <td align='center'><b>$sum_n2</b></td>
      </tr>";

	?>

    </tbody>
  </table>

  </div>
</div>