2015-12-19 34 views
0
<?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在哪里?DOMDocument无法从数据库获取所有记录

这是我的输出:

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ł 

回答

0

你可以尝试改变:

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

while($c = $filter->fetch()){ 

你不超出资源的界限的方式。

+0

好的,谢谢:) 但是,仍然无法获得4条记录,只有3 :( – MrGohut