I am unable to reiterate the exploded lat and lng values. Keeps returning only one pair of (x,y) values in the database.
Please see the code below:
<?php
$feed = file_get_contents("http://api.geograph.org.uk/syndicator.php?key=hfALmNnpQ&i=14102530&page=1&format=media&expand=1&perpage=100");
$xml = new SimpleXmlElement($feed);
foreach ($xml->item as $entry){
echo $entry->title;
echo $entry->description;
echo $entry->link;
// use that namespace
$dc = $entry->children('http://purl.org/dc/elements/1.1/');
$georss = $entry->children('http://www.georss.org/georss');
echo $entry->children('http://purl.org/dc/elements/1.1/')->creator;
echo $entry->children('http://www.georss.org/georss')->point
list($lat,$lng) = explode(' ', $entry->children('http://www.georss.org/georss')->point);
}
?>
The code below shows the database operations:
<?php
require 'table.php';
// Opens a connection to a PostgresSQL server
$connection = pg_connect("dbname=postgis user=postgres password=****");
// Execute query
foreach ($xml->item as $entry) {
$query = "INSERT INTO geognew(title, link, author, latitude, longitude) VALUES ('" . $entry->title . "', '" . $entry->link . "', '" . $entry->children('http://purl.org/dc/elements/1.1/')->creator . "', '" . $lat . "', '" . $lng . "')";
$result = pg_query($query);
printf ("These values are inserted into the database - %s %s %s", $entry->title, $entry->link, $entry->children('http://purl.org/dc/elements/1.1/')->creator, $lat, $lng);
}
pg_close();
?>
Thanks
Yemi
Its better you save the lat/lng in an array. Because iterating the xml over and over is a overkill.
Here is a full code that iterates only through latitude and longitude.