【发布时间】:2017-09-05 05:01:32
【问题描述】:
我正在建立一个网站,它从另一个网站抓取数据,将其存储在数据库中并以表格的形式显示。只要行数较少(大约 100 行),一切正常,但是当数据集增加时,比如 300 行或更多行,数据会存储在数据库(phpmyadmin)中,但屏幕上什么都没有显示,网站只是保持加载。下面是我正在运行的 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()。
【问题讨论】:
标签: php html mysqli phpmyadmin