Hola, tengo un problema al extraer datos de una web y guardarlos en una BD.
Solo me guarda el último registro.
Dejo el código que estoy utilizando por si me podeis ayudar en lo que estoy fallando.
Gracias
Código PHP:
Ver original<?php
require("phpsqlsearch_dbinfo.php");
if (!$connection) {
}
// Set the active mySQL database
if (!$db_selected) {
}
$extrae = $_POST['url'];
$type = $_POST['type'];
$provincias = $_POST['county'];
$paises = $_POST['country'];
// Use internal libxml errors -- turn on in production, off for debugging
// Createa a new DomDocument object
$dom = new DomDocument;
// Load the HTML
$dom->loadHTMLFile($extrae);
// Create a new XPath object
$xpath = new DomXPath($dom);
//Query all <td> nodes containing specified class name
$titulos = $xpath->query('//a[@class="url"]');
$telefonos = $xpath->query('//p[@class="tel"]');
$direcciones = $xpath->query('//span[@class="street-address"]');
$ciudades = $xpath->query('//a[@class="locality"]');
$lats = $xpath->query('//span[@class="latitude hidden"]');
$lngs = $xpath->query('//span[@class="longitude hidden"]');
// Set HTTP response header to text/html for debugging output
header('Content-type: text/html; charset=utf-8'); //Traverse the DOMNodeList object to output each DomNode's nodeValue
foreach ($titulos as $titulo) {
$name = ltrim($titulo->nodeValue); //echo $name."<br>";
}
foreach ($direcciones as $direccion) {
$address = $direccion->nodeValue;
//echo $address."<br>";
}
foreach ($ciudades as $ciudad) {
$city = $ciudad->nodeValue;
//echo $city." ".$provincias." ".$paises."<br>";
}
foreach ($telefonos as $telefono) {
$phone = $telefono->nodeValue;
//echo $phone."<br>";
}
foreach ($lats as $lat) {
$latitud = $lat->nodeValue;
//echo $latitud."<br>";
}
foreach ($lngs as $lng) {
$longitud = $lng->nodeValue;
//echo $longitud."<br>";
}
$sqlins = "INSERT INTO markersprueba (name, type, address, city, county, country, phone, lat, lng, fecAlta) ".
"VALUES ('$name', '$type', '$address', '$city', '$provincias', '$paises', '$phone', '$latidud', '$longitud', CURDATE())";
?>