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;
- }
- 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);
- if ($result) {
- // $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++) {
- // echo substr($xlKetqua[$i], -2) . "-";
- // // if ($i % 10 == 0) echo "<br>";
- // }
- // echo "<br><br><br>";
- 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 {
- $response["success"] = 0;
- $response["message"] = "Error";
- echo json_encode($response);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment