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 8917507
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:30:09+00:00 2026-06-15T05:30:09+00:00

HI i have a peice of code which takes information from a xml file

  • 0

HI i have a peice of code which takes information from a xml file using the below peice of code:

if (file_exists('locations.xml')) {
    $xml = simplexml_load_file('locations.xml');
    $json = json_encode($xml);
    print_r($json);
} else {
    exit('Failed to open locations.xml.');
}

Below is the layout of the xml page

   <locations>
     <location>
       <id>12196</title>
       <uid>010203</uid>
       <lat>34.134103</lat>
       <lng>-118.321694</lng>
      </location>
    <location>

This works fine, now what i want to do is replace the code above to take information straight from the database. and have the following peice of Code:

  $query = mysql_query("SELECT * FROM track ORDER BY id");
  $rows = array();
  while($row = mysql_fetch_assoc($query)) {
   $rows[] = $row;
  }
  print json_encode($rows);

When retrieving the information from the database it works well. However i have noticed that when i retrieve the data the format is slightly different for example.

using the first method places location in front of the results, like this.

  {"location":[{"id":"12196"

and the second method just returns this,

  [{"id":"12196","uid":"010203"

I have tried severals ways to get the second format to include the location, but can not seem to get it to work. and i think the rest of my code uses the location tag to assign the information.

Any suggestions would be appreciated.

Thanks

  • 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-06-15T05:30:11+00:00Added an answer on June 15, 2026 at 5:30 am

    Try

    while($row = mysql_fetch_assoc($query)) {
       $rows['location'][] = $row;
      }
      print json_encode($rows);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a piece of code which takes an IP address (from main
I have a piece of matlab code below which reads data from a table.
I have this piece of code which check the last customer_id from the db.
I have a piece of code which returns a Sales Order from AX. In
Ok i have this piece of code from which i took from W3schools :-
I have written a small XML validator, that takes in an XML file and
I have written some code in which a small part of the code takes
I have this piece of Javascript code, which takes about 600 ms on every
I have this piece of sh code which takes one argument at a time:
I'm writing a small piece of code which takes input from a user via

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.