Jump to content

MrGohut

New Members
  • Posts

    4
  • Joined

  • Last visited

Everything posted by MrGohut

  1. Hmm okay, i fixed it. Now it works fine. Thanks I'll do that.
  2. <?php ini_set('display_errors', 1); error_reporting(E_ALL); require_once ('../includes/connect.php'); try { $filter = $db->query("SELECT * FROM procesory"); $check = $filter->rowCount(); echo $check.'<br />'; while($c = $filter->fetch()){ $source = file_get_contents($c['pURLMorele']); $doc = new DomDocument(); $file = @$doc->loadHTML($source); $rows = $doc->getElementsByTagName('span'); foreach ($rows as $row) { if($row->getAttribute('class') == 'price') { echo $c['ID'].' - '; echo $row->nodeValue.' -- OK!<br />'; $id = $c['ID']; $price = $row->nodeValue; $update = $db->prepare("UPDATE procesory SET pPrice=:price WHERE ID=:id"); $update->bindValue(':price', $price); $update->bindValue(':id', $id); $update->execute(); } } } } catch (PDOException $e) { echo 'Something went wrong!<br>'.$e->getMessage(); die(); } ?> I think that's better, but still.. All the time ID from 2 to 4 and i need from 1 to 4 :/
  3. Okay so.. 1. I'm getting URL from my database $c['pURLMorele']; 2. i'm entering on that website and getting text in SPAN with class "price" 3. I'm showing that text on my website. I repaired it: <?php ini_set('display_errors', 1); error_reporting(E_ALL); require_once ('../includes/connect.php'); try { $filter = $db->query("SELECT * FROM procesory"); $check = $filter->rowCount(); echo $check.'<br />'; while($c = $filter->fetch()){ //echo $c['ID']; $XMLDoc = new DOMDocument(); $source = file_get_contents($c['pURLMorele']); libxml_use_internal_errors(true); $XMLDoc->loadHTML($source); $xpath = new DOMXPath($XMLDoc); $rows = $xpath->query("//span[@class='price']"); foreach ($rows as $row) { echo $c['ID'].' - '; print_r($row->textContent.' -- OK!<br />'); } } } catch (PDOException $e) { echo 'Something went wrong!<br>'.$e->getMessage(); die(); } ?> But the problem is that this is doing only 3 of 4 rows: http://scr.hu/3tpn/e2vu1 http://scr.hu/3tpn/7ychi I hope you get it now XD I'm not very good at explaining. I used docs about it and some examples from stackoverflow
  4. <?php ini_set('display_errors', 1); error_reporting(E_ALL); require_once ('../includes/connect.php'); try { $filter = $db->query("SELECT * FROM procesory"); $check = $filter->rowCount(); echo $check.'<br />'; while($c = $filter->fetch()){ //echo $c['ID']; $XMLDoc = new DOMDocument(); $source = $c['pURLMorele']; $XMLDoc->loadHTML($source); $xpath = new DOMXPath($XMLDoc); $rows = $xpath->query("//span[@class='price']"); foreach ($rows as $row) { var_dump($row->nodeValue); } } } catch (PDOException $e) { echo 'Something went wrong!<br>'.$e->getMessage(); die(); } ?> I've got database, table "procesory" and there are 4 records. I need to get from each one of them "pURLMorele" column and from URL in this column show on my site text from span.class="price". Now... This code won't work. I only shows "4" from echo. Any ideas?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.