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";
- }
- 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){
- // echo "Dac biet";
- // $thongke la luot xuat hien
- for ($i = 0; $i < 100; $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 (substr($xlKetqua[$i], -2, 1) == 0) {
- $hai2so = substr($xlKetqua[$i], -1);
- } else {
- $hai2so = substr($xlKetqua[$i], -2);
- }
- $thongke[$hai2so]++;
- }
- }
- // Dua ra day so
- $dayso = "";
- for ($i = 0; $i <= 9; $i++) {
- $dayso = $dayso . "0" . $i . ",";
- }
- for ($i = 10; $i <= 98; $i++) {
- $dayso = $dayso . $i . ",";
- }
- $dayso = $dayso . "99";
- // Tinh luot xuat hien
- $dayxuathien = "";
- for ($i = 0; $i <= 98; $i++) {
- $dayxuathien = $dayxuathien . $thongke[$i] . ",";
- }
- $dayxuathien = $dayxuathien . $thongke[99];
- // Tinh phan tram xuat hien
- $tong = 0;
- for ($i = 0; $i <= 99; $i++) {
- $tong = $tong + $thongke[$i];
- }
- if ($tong==0){
- $tong=1;
- }
- for ($i = 0; $i <= 99; $i++) {
- $phantram[$i] = $thongke[$i] / $tong * 100;
- $phantram[$i] = round($phantram[$i], 2);
- }
- $dayphantram = "";
- for ($i = 0; $i <= 98; $i++) {
- $dayphantram = $dayphantram . $phantram[$i] . ",";
- }
- $dayphantram = $dayphantram . $phantram[99];
- // 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 < 100; $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 (substr($xlKetqua[$i], -2, 1) == 0) {
- $hai2so = substr($xlKetqua[$i], -1);
- } else {
- $hai2so = substr($xlKetqua[$i], -2);
- }
- $thongke[$hai2so]++;
- }
- }
- // Dua ra day so
- $dayso = "";
- for ($i = 0; $i <= 9; $i++) {
- $dayso = $dayso . "0" . $i . ",";
- }
- for ($i = 10; $i <= 98; $i++) {
- $dayso = $dayso . $i . ",";
- }
- $dayso = $dayso . "99";
- // Tinh luot xuat hien
- $dayxuathien = "";
- for ($i = 0; $i <= 98; $i++) {
- $dayxuathien = $dayxuathien . $thongke[$i] . ",";
- }
- $dayxuathien = $dayxuathien . $thongke[99];
- // Tinh phan tram xuat hien
- $tong = 0;
- for ($i = 0; $i <= 99; $i++) {
- $tong = $tong + $thongke[$i];
- }
- for ($i = 0; $i <= 99; $i++) {
- $phantram[$i] = $thongke[$i] / $tong * 100;
- $phantram[$i] = round($phantram[$i], 2);
- }
- $dayphantram = "";
- for ($i = 0; $i <= 98; $i++) {
- $dayphantram = $dayphantram . $phantram[$i] . ",";
- }
- $dayphantram = $dayphantram . $phantram[99];
- // 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);
- } else if ($loai == "nhatto") {
- EchoJson(1,1,$result);
- } else if ($loai == "haicua") {
- EchoJson(0,1,$result);
- } 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