Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (isset($_GET["vung"])) {
- $vung = $_GET["vung"]; // noi lay ket qua xo so
- } else {
- $vung = "xo-so-mien-bac";
- }
- if (isset($_GET["limit"])) {
- $limit = $_GET["limit"]; // so ngay cach day
- } else {
- $limit = 1;
- }
- if (isset($_GET["loai"])) {
- $loai = $_GET["loai"]; // lo, dac biet, nhat to, hai cua
- } else {
- $loai = "lo";
- }
- if (isset($_GET["dauduoi"])) {
- $dauduoi = $_GET["dauduoi"]; // dau, duoi
- } else {
- $dauduoi = "duoi";
- }
- require_once __DIR__ . '/db_config.php';
- // Ket noi database de lay du lieu
- $conn = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die("Can't connect this database");
- mysql_select_db("appxoso", $conn);
- $vung = str_replace("-", "", $vung);
- $sql = "SELECT * FROM $vung ORDER BY pid DESC LIMIT $limit";
- $result = mysql_query($sql);
- function EchoJson($iStart, $iEnd, $result, $dauduoi)
- {
- // $thongke la luot xuat hien
- for ($i = 0; $i <= 9; $i++) {
- $thongke[$i] = 0;
- }
- // Lay truong ket qua ra de xu ly
- while ($row = mysql_fetch_array($result)) {
- $ketqua = $row["ketqua"];
- $ketqua = str_replace("-", ",", $ketqua);
- $xlKetqua = explode(",", $ketqua);
- for ($i = $iStart; $i <= $iEnd; $i++) {
- if ($dauduoi == "duoi") {
- $hai2so = substr($xlKetqua[$i], -1);
- } else {
- $hai2so = substr($xlKetqua[$i], -2, 1);
- }
- $thongke[$hai2so]++;
- }
- }
- // Tinh phan tram
- $tong = 0;
- for ($i = 0; $i <= 9; $i++) {
- $tong = $tong + $thongke[$i];
- }
- if ($tong == 0) {
- $tong = 1;
- }
- for ($i = 0; $i <= 9; $i++) {
- $phantram[$i] = $thongke[$i] / $tong * 100;
- $phantram[$i] = round($phantram[$i], 2);
- }
- // Kiem tra xem dung chua
- // for ($i = 0; $i <= 9; $i++) {
- // echo $i . " - " . $thongke[$i] . " - " . $phantram[$i] . "<br>";
- // }
- // Dua ra day so
- $dayso = "";
- for ($i = 0; $i <= 8; $i++) {
- $dayso = $dayso . $i . ",";
- }
- $dayso = $dayso . "9";
- // Dua luot xuat hien
- $dayxuathien = "";
- for ($i = 0; $i <= 8; $i++) {
- $dayxuathien = $dayxuathien . $thongke[$i] . ",";
- }
- $dayxuathien = $dayxuathien . $thongke[9];
- // Dua phan tram xuat hien
- $dayphantram = "";
- for ($i = 0; $i <= 8; $i++) {
- $dayphantram = $dayphantram . $phantram[$i] . ",";
- }
- $dayphantram = $dayphantram . $phantram[9];
- // echo $dayso . "<br>";
- // echo $dayxuathien . "<br>";
- // echo $dayphantram . "<br>";
- $response["success"] = 1;
- $response["message"] = array();
- $kq["dayso"] = $dayso;
- $kq["dayxuathien"] = $dayxuathien;
- $kq["dayphantram"] = $dayphantram;
- array_push($response["message"], $kq);
- echo json_encode($response);
- }
- if ($result) {
- if ($loai == "lo") {
- // $thongke la luot xuat hien
- for ($i = 0; $i <= 9; $i++) {
- $thongke[$i] = 0;
- }
- // Lay truong ket qua ra de xu ly
- while ($row = mysql_fetch_array($result)) {
- $ketqua = $row["ketqua"];
- $ketqua = str_replace("-", ",", $ketqua);
- $xlKetqua = explode(",", $ketqua);
- for ($i = 0; $i < count($xlKetqua); $i++) {
- if ($dauduoi == "duoi") {
- $hai2so = substr($xlKetqua[$i], -1);
- } else {
- $hai2so = substr($xlKetqua[$i], -2, 1);
- }
- $thongke[$hai2so]++;
- }
- }
- // Tinh phan tram
- $tong = 0;
- for ($i = 0; $i <= 9; $i++) {
- $tong = $tong + $thongke[$i];
- }
- if ($tong == 0) {
- $tong = 1;
- }
- for ($i = 0; $i <= 9; $i++) {
- $phantram[$i] = $thongke[$i] / $tong * 100;
- $phantram[$i] = round($phantram[$i], 2);
- }
- // Kiem tra xem dung chua
- // for ($i = 0; $i <= 9; $i++) {
- // echo $i . " - " . $thongke[$i] . " - " . $phantram[$i] . "<br>";
- // }
- // Dua ra day so
- $dayso = "";
- for ($i = 0; $i <= 8; $i++) {
- $dayso = $dayso . $i . ",";
- }
- $dayso = $dayso . "9";
- // Dua luot xuat hien
- $dayxuathien = "";
- for ($i = 0; $i <= 8; $i++) {
- $dayxuathien = $dayxuathien . $thongke[$i] . ",";
- }
- $dayxuathien = $dayxuathien . $thongke[9];
- // Dua phan tram xuat hien
- $dayphantram = "";
- for ($i = 0; $i <= 8; $i++) {
- $dayphantram = $dayphantram . $phantram[$i] . ",";
- }
- $dayphantram = $dayphantram . $phantram[9];
- // echo $dayso . "<br>";
- // echo $dayxuathien . "<br>";
- // echo $dayphantram . "<br>";
- $response["success"] = 1;
- $response["message"] = array();
- $kq["dayso"] = $dayso;
- $kq["dayxuathien"] = $dayxuathien;
- $kq["dayphantram"] = $dayphantram;
- array_push($response["message"], $kq);
- echo json_encode($response);
- } else if ($loai == "dacbiet") {
- EchoJson(0, 0, $result, $dauduoi);
- } else if ($loai == "nhatto") {
- EchoJson(1, 1, $result, $dauduoi);
- } else if ($loai == "haicua") {
- EchoJson(0, 1, $result, $dauduoi);
- } else {
- $response["success"] = 0;
- $response["message"] = "Error";
- echo json_encode($response);
- }
- } else {
- $response["success"] = 0;
- $response["message"] = "Error";
- echo json_encode($response);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment