<?php
    require '../../data.php';
    if(isset($_GET['pasar'])) {
        $pasar = mysqli_real_escape_string($data, $_GET['pasar']);

        $spa = "SELECT * FROM (SELECT * FROM result_lotto ORDER BY res_jam DESC LIMIT 698) tmp WHERE tmp.res_pasaran = '$pasar' ORDER BY tmp.res_jam ASC";
        $qpa = mysqli_query($data, $spa);

        if(mysqli_num_rows($qpa) > 0) {

            function timeindo($jamnya) {
                $hari = date("l", strtotime($jamnya));
            
                switch($hari){
                    case 'Monday':
                        return 'Senin';
                    break;
            
                    case 'Tuesday':
                        return 'Selasa';
                    break;
            
                    case 'Wednesday':
                        return 'Rabu';
                    break;
            
                    case 'Thursday':
                        return 'Kamis';
                    break;
            
                    case 'Friday':
                        return 'Jumat';
                    break;
            
                    case 'Saturday':
                        return 'Sabtu';
                    break;
            
                    case 'Sunday':
                        return 'Minggu';
                    break;
                }
            
            }
            $regex = '/(?<!\ )[a-zA-Z0-9]/';
            
            while($fpa = mysqli_fetch_assoc($qpa)) {
                $resdate = $fpa['res_jam'];
                $resangka = $fpa['res_angka'];

                $seperate = str_split($resangka);

                $kepala = $seperate[2];

                $ekor = $seperate[3];

            
                
                echo '<div id="resultday">
                    '.timeindo($resdate).'
                </div>
                
                    <div id="resultdate">
                        '.date("Y-m-d", strtotime($resdate)).'
                    </div>';

                    $num1 = preg_replace($regex, '<td class="paito-num p-num">\\0</td>'.'' , $resangka);

                    echo '<div id="resultangka">';
                    echo $num1;
                    
                    if($kepala == 'x' && $ekor == 'x') {
                        echo '<td class="paito-num addi-paito">-</td>';
                        
                    } else if($kepala + $ekor > 9) {
                        $kalkulasi = $kepala + $ekor;
                            $sep = str_split($kalkulasi);
                            $hpaito = $sep[0] + $sep[1];
                        echo '<td class="paito-num addi-paito">'.$hpaito.'</td>';
                        
                    }else {
                        $count = $kepala + $ekor;
                        echo '<td class="paito-num addi-paito">'.$count.'</td>';
                    }
                    echo '</div>';
            }
        }
    }
?>