分解された緯度と経度の値を繰り返し表示できません。データベース内に1組の(x、y)値のみを返します。分解された値を反復する
以下のコードを参照してください。
<?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);
}
?>
次のコードは、データベース操作を示しています
<?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();
?>
おかげ Yemi
ループ内にデータベース操作がないと仮定すると、ループによって処理されたLASTペアであるループ終了後に** 1 **緯度/経度のペアが得られます。 –
'echo'文の出力を表示します。 –
* APIキーを削除する* –