thieumao

Thong ke 00-99

Dec 9th, 2013
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.02 KB | None | 0 0
  1. <?php
  2.  
  3. $vung  = $_GET["vung"]; // noi lay ket qua xo so
  4. $limit = $_GET["limit"]; // so ngay cach day
  5. // $thongke la luot xuat hien
  6. for ($i = 0; $i < 100; $i++) {
  7.     $thongke[$i] = 0;
  8. }
  9.  
  10. require_once __DIR__ . '/db_config.php';
  11.  
  12. // Ket noi database de lay du lieu
  13. $conn = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die("Can't connect this database");
  14. mysql_select_db("appxoso", $conn);
  15. $vung   = str_replace("-", "", $vung);
  16. $sql    = "SELECT * FROM $vung ORDER BY pid DESC LIMIT $limit";
  17. $result = mysql_query($sql);
  18.  
  19. // Lay truong ket qua ra de xu ly
  20. while ($row = mysql_fetch_array($result)) {
  21.     $ketqua   = $row["ketqua"];
  22.     $ketqua   = str_replace("-", ",", $ketqua);
  23.     $xlKetqua = explode(",", $ketqua);
  24.    
  25.     // for ($i = 0; $i < count($xlKetqua); $i++) {
  26.     //     echo substr($xlKetqua[$i], -2) . "-";
  27.     //     // if ($i % 10 == 0) echo "<br>";
  28.     // }
  29.     // echo "<br><br><br>";
  30.    
  31.     for ($i = 0; $i < count($xlKetqua); $i++) {
  32.         if (substr($xlKetqua[$i], -2, 1) == 0) {
  33.             $hai2so = substr($xlKetqua[$i], -1);
  34.         } else {
  35.             $hai2so = substr($xlKetqua[$i], -2);
  36.         }
  37.         $thongke[$hai2so]++;
  38.     }
  39. }
  40.  
  41. // Dua ra day so
  42. $dayso = "";
  43. for ($i = 0; $i <= 9; $i++) {
  44.     $dayso = $dayso . "0" . $i . ",";
  45. }
  46. for ($i = 10; $i <= 98; $i++) {
  47.     $dayso = $dayso . $i . ",";
  48. }
  49. $dayso = $dayso . "99";
  50.  
  51. // Tinh luot xuat hien
  52. $dayxuathien = "";
  53. for ($i = 0; $i <= 98; $i++) {
  54.     $dayxuathien = $dayxuathien . $thongke[$i] . ",";
  55. }
  56. $dayxuathien = $dayxuathien . $thongke[99];
  57.  
  58. // Tinh phan tram xuat hien
  59. $tong = 0;
  60. for ($i = 0; $i <= 99; $i++) {
  61.     $tong = $tong + $thongke[$i];
  62. }
  63. for ($i = 0; $i <= 99; $i++) {
  64.     $phantram[$i] = $thongke[$i] / $tong * 100;
  65.     $phantram[$i] = round($phantram[$i], 2);
  66. }
  67. $dayphantram = "";
  68. for ($i = 0; $i <= 98; $i++) {
  69.     $dayphantram = $dayphantram . $phantram[$i] . ",";
  70. }
  71. $dayphantram = $dayphantram . "99";
  72.  
  73. echo $dayso . "<br>";
  74. echo $dayxuathien . "<br>";
  75. echo $dayphantram . "<br>";
  76.  
  77. ?>
Advertisement
Add Comment
Please, Sign In to add comment