Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7605071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:04:26+00:00 2026-05-31T00:04:26+00:00

I am unable to reiterate the exploded lat and lng values. Keeps returning only

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T00:04:27+00:00Added an answer on May 31, 2026 at 12:04 am

    Its better you save the lat/lng in an array. Because iterating the xml over and over is a overkill.

    // define this $points outside the foreach loop
    $points = array();
    
    foreach(...){
    ....
        list($lat,$lng) = explode(' '
               , (string)($entry->children('http://www.georss.org/georss')->point));
        $points[] = array('lat'=> $lat, 'long' => $lng);
    }
    

    Here is a full code that iterates only through latitude and longitude.

    $xml = simplexml_load_string($feed);
    $namespaces = $xml->getNameSpaces(true);
    foreach ($xml->item as $entry){
        $georss = $entry->children($namespaces['georss']);
        list($lat,$lng) = explode(' ', (string)$georss->point);
        echo "$lat, $lng\n";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am unable to find the implementation of llvm.pow.f64 function. I want to see
Unable to connect to your database server using the provided settings. I've been having
Unable to understand. Why output is equal code: if (-3 == ~2) Console.WriteLine(equal); else
Am unable to understand why Cannot the below javascript code is not called from
I'm unable to find file.ReadLine function in Go. How does one read a file
Unable to remove this error, nothing is working although the same code is working
Iam unable to understand following: $this->db->select('1', FALSE); Can some one elaborate it in simple
I am unable to send any command through smtp.gmail.com. I can see some mixed
Unable to connect to our company MSSQL server from one of our FreeBSD servers.
I unable to use put method to send data to particular link.. Please find

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.