<?php
include "control/activity.php";
$dd = new activity();

?>

<table class="table table-bordered data-table">
<tr>
    <td><center>Number</center></td>
    <td><center>Bet Amount</center></td>
    <td><center>Win Amount</center></td>
    <td><center>Selected Number</center></td>
</tr>
<?php
    $gggmm = $_REQUEST['game'];
    $table = "account_history";
    $condition = " where gameNumber='$gggmm' AND game_name='TRX' AND status='pending'";
    $getHistory = $dd->fetch_multi($table,$condition);
    $secondArray  = array();
    foreach($getHistory as $key){
        $secondArray[] = array("bet_amount" => $key->bet_amount,"amount" => $key->amount,"lossorprofit" => $key->lossorprofit,"selected_number" => $key->selected_number);
    }
    
    
    $firstArray  = array();
    for($i=0; $i < 10; $i++){
        $firstArray[] = array("bet_amount" =>0,"amount" => 0,"lossorprofit" => 0, "selected_number" => $i);
    }
    
    foreach ($secondArray as $entry) {
    foreach ($firstArray as &$item) {
        if ($item["selected_number"] == $entry["selected_number"]) {
            $item["bet_amount"] += $entry["bet_amount"];
            $item["amount"] += $entry["amount"];
            $item["lossorprofit"] += $entry["lossorprofit"];
        }
    }
   }
  
  foreach($firstArray as $key){
?>
<tr>
    <td><center><?= $key['selected_number']; ?></center></td>
    <td><center>₹<?= $key['bet_amount']; ?></center></td>
    <td><center>₹<?= $key['lossorprofit']; ?></center></td>
    <td><center><div style="width:10px; height:10px; background:black;"/></center></td>
</tr>
<?php } ?>
</table>