thieumao

getDataChiTietTySo.php

Mar 28th, 2014
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.61 KB | None | 0 0
  1. <?php
  2. echo "Thieu Mao<br>";
  3. $tenbang = "livescoretrandau";
  4. $tenbang2 = "livescorechitiettrandau";
  5. //<< 1- Ket noi DB
  6. include ('db_config.php');
  7. $conn = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die("Can't connect this database");
  8. mysql_select_db(DB_DATABASE, $conn);
  9. mysql_set_charset('utf8',$conn);
  10. //>> 1- Ket noi DB
  11.  
  12. $sth = mysql_query("SELECT * FROM `".$tenbang."`");
  13. $rows = array();
  14. while($r = mysql_fetch_assoc($sth)) {
  15.     $rows[] = $r;
  16. }
  17.  
  18. $count = count($rows);
  19. $arrLink = array();
  20. $arridTranDau = array();
  21. for ($i=0;$i<$count;$i++){
  22.     $arrLink[$i] = $rows[$i]["Link"];
  23.     $arridTranDau[$i] = $rows[$i]["idTranDau"];
  24.     //echo $i . " : " . $arrLink[$i] . " - ". $arridTranDau[$i] ."<br>";
  25. }
  26.  
  27. include('../simplehtmldom/simple_html_dom.php');
  28. $linkTySo="http://www.livescore.com/soccer/italy/serie-a/sassuolo-vs-sampdoria/1-1536817/";
  29. $html = file_get_html($linkTySo);
  30. //table  class="match-details match-ellipsis league-table mtn"
  31. foreach($html->find('table[class="match-details match-ellipsis league-table mtn"]') as $e) {
  32.     $chtml =  str_get_html($e->innertext);
  33.     break;
  34. }
  35.  
  36. $i=0;
  37. foreach($chtml->find('span[class="team"]') as $e) {
  38.     $i++;
  39.     if ($i==1){
  40.         $Doi1 = trim($e->plaintext);
  41.     }
  42.     if ($i==2){
  43.         $Doi2 = trim($e->plaintext);
  44.         break;
  45.     }
  46. }
  47. $i=0;
  48. foreach($chtml->find('tr') as $e) {
  49.     $Phut = "";
  50.     $TySo = "";
  51.     $CauThu1 = "";
  52.     $CauThu2 = "";
  53.     $Bong1 = 0;
  54.     $Bong2 = 0;
  55.     $Vang1 = 0;
  56.     $Vang2 = 0;
  57.     $Do1 = 0;
  58.     $Do2 = 0;
  59.     $VangDo1 = 0;
  60.     $VangDo2 = 0;
  61.  
  62.     $c2html= str_get_html($e->innertext);
  63.     foreach($c2html->find('td[class="min"]') as $e) {
  64.         $Phut = trim($e->plaintext);
  65.     }
  66.     foreach($c2html->find('td[class="sco"]') as $e) {
  67.         $TySo = trim($e->plaintext);
  68.     }
  69.     foreach($c2html->find('span[class="right name"]') as $e) {
  70.         $CauThu1 = trim($e->plaintext);
  71.     }
  72.     foreach($c2html->find('span[class="left name"]') as $e) {
  73.         $CauThu2 = trim($e->plaintext);
  74.     }
  75.     foreach($c2html->find('span[class="inc goal right"]') as $e) {
  76.         $Bong1=1;
  77.     }
  78.     foreach($c2html->find('span[class="inc goal left"]') as $e) {
  79.         $Bong2=1;
  80.     }
  81.     foreach($c2html->find('span[class="inc yellowcard right"]') as $e) {
  82.         $Vang1=1;
  83.     }
  84.     foreach($c2html->find('span[class="inc yellowcard left"]') as $e) {
  85.         $Vang2=1;
  86.     }
  87.     foreach($c2html->find('span[class="inc redcard right"]') as $e) {
  88.         $Do1=1;
  89.     }
  90.     foreach($c2html->find('span[class="inc redcard left"]') as $e) {
  91.         $Do2=1;
  92.     }
  93.     foreach($c2html->find('span[class="inc redyellowcard right"]') as $e) {
  94.         $VangDo1=1;
  95.     }
  96.     foreach($c2html->find('span[class="inc redyellowcard left"]') as $e) {
  97.         $VangDo2=1;
  98.     }
  99.  
  100.     //---------------------------//
  101.     if (strlen($Phut)>0){
  102.         $i++;
  103.         /*
  104.          echo "i=$i ::  Link: $linkTySo - Doi 1: $Doi1 - Doi2: $Doi2 : ";
  105.          echo "- Phut: " . $Phut;
  106.          echo " - Ty so: " . $TySo;
  107.          echo " - Cauthu1: ". $CauThu1;
  108.          echo " - Cauthu2: ". $CauThu2;
  109.          echo " -> Bong1: ". $Bong1 . "<br>";
  110.          echo " -> Bong2: ". $Bong2 . "<br>";
  111.          echo " -> Vang1: ". $Vang1 . "<br>";
  112.          echo " -> Vang2: ". $Vang2 . "<br>";
  113.          echo " -> Do1: ". $Do1 . "<br>";
  114.          echo " -> Do2: ". $Do2 . "<br>";
  115.          echo " -> VangDo1: ". $VangDo1 . "<br>";
  116.          echo " -> VangDo2: ". $VangDo2 . "<br>";
  117.          */
  118.  
  119.         $sqlinsert = "INSERT INTO `tivi`.`livescorechitiettrandau` (
  120.                 `idTranDau`, `Link`, `Doi1`, `Doi2`, `Phut`, `TySo`, `CauThu1`, `CauThu2`, `Bong1`, `Bong2`, `Vang1`, `Vang2`, `Do1`, `Do2`, `VangDo1`, `VangDo2`)
  121.         VALUES ('$idTranDau','$Link', '$Doi1', '$Doi2', '$Phut', '$TySo', '$CauThu1', '$CauThu2', '$Bong1', '$Bong2', '$Vang1', '$Vang2', '$Do1', '$Do2', '$VangDo1', '$VangDo2');";
  122.         echo $sqlinsert . "<br><br>";
  123.         //mysql_query($sqlinsert);
  124.     }
  125. }
Advertisement
Add Comment
Please, Sign In to add comment