2017-04-10 12 views
0

私は別のウェブサイトからデータをスクラップしてデータベースに保存し、それをテーブルの形で表示するウェブサイトを構築しています。行の数が少ない(約100)限り、すべてが正常に動作しますが、データセットが増加すると、300行以上のデータがデータベース(phpmyadmin)に格納されますが、画面上に何も表示されず、読み込み中。以下は、私が実行しているPHPスクリプトのセクションです:私はすでに私のDBに格納されたデータを持っていると私はちょうどそれを取得して印刷する場合大きなデータセットのためにPHPスクリプトが掛かっています

<?php 

// configuration 
require("../includes/helpers.php"); 

     // initializing current page and number of pages 
     $page = 0; 
     $pages = 1; 

     // scrape data from each page 
     while($pages--) 
     { 
      // next page 
      $page++; 

      // scrape data from shiksha.com 
      $string = @file_get_contents("http://www.shiksha.com/b-tech/colleges/b-tech-colleges-".urlencode($_POST["city"])."-{$page}"); 

      if($string === false) 
       apologize("Please enter a valid city name"); 

      if($page === 1) 
      { 
       // counting total number of pages 
       preg_match_all('/class=" linkpagination">/',$string,$result); 
       $pages = sizeof($result[0]); 
      } 

      // passing the string for scraping data and storing in database 
      get_college_info($string,$page); 

      // delay for 2s 
      sleep(2); 
     } 


     // querying the infrastructure table for facilities of all colleges 
     $infra = query("SELECT college_id,facilities FROM infrastructure "); 

     // preparing query and selecting data from table college_info 
     $result = query("SELECT * FROM college_info"); 

     // render(output) results 
     render("result.php",["title" => "result","infra" => $infra,"result" => $result]); 
    } 
}?> 

興味深いことに、すべてが正常に動作し、すべてのデータは、しかし、大きな、それは、印刷されます。私は問題が何か分からない。 PS:set_time_limit()を試しました。

答えて

0

無限ループを作成しています。この問題を解決するには、whileループの基準を以下に変更してください。

while($page<$pages) 
{ 
    //your same code here 
} 
+0

私は問題を考えていませんが、とにかく試してみましたが、まだ動作していません。 @ user3299379 –

関連する問題