<?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();
}
?>
In my database are 4 records, but i don't know why it's showing me only 3 of them (2, 3 ,4). Where is 1?!
This is my output:
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ł
You could try changing:
for($i = 1; $i < $check+1; $i++){
$c = $filter->fetch();
to
while($c = $filter->fetch()){
That way you're not exceeding the bounds of the resource.