DOMDocument无法从数据库中获取所有记录

时间:2015-12-19 20:04:23

标签: php dom

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
require_once ('../includes/connect.php');
try {
    $filter = $db->query("SELECT * FROM table");
    $check = $filter->rowCount();
    echo $check.'<br />';
    for($i = 1; $i < $check+1; $i++){
        $c = $filter->fetch();
        //echo $c['ID'];
        $source = file_get_contents($c['pURLMorele']);
        $dom = new DOMDocument();
        @$dom->loadHTML($source);
        $xpath = new DOMXPath($dom);

        $rows = $xpath->query("//span[@class='price']");

        print_r($rows->item(0)->textContent);
    }
}
catch (PDOException $e) {
    echo 'Something went wrong!<br>'.$e->getMessage();
    die();
}
?>

在我的数据库中有4条记录,但我不知道它为什么只显示其中的3条(2,3,4)。哪里是1?!

这是我的输出:

4
Notice: Trying to get property of non-object in /var/www/vhosts/20/147910/webspace/httpdocs/serwer151299580.twojeaz.pl/functions/pricesUpdate.php on line 19
515,00 zł 269,00 zł 1589,00 zł

1 个答案:

答案 0 :(得分:0)

您可以尝试更改:

googlesearch_settings.py

for($i = 1; $i < $check+1; $i++){
    $c = $filter->fetch();

这样你就不会超出资源的界限。