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

  • Home
  • SEARCH
  • 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 7504659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:38:45+00:00 2026-05-29T21:38:45+00:00

Ok so i have a php script: <?php mysql_connect(localhost,root,root); mysql_select_db(FYP); $sql=mysql_query(select team_name, games_played, games_won,

  • 0

Ok so i have a php script:

<?php
  mysql_connect("localhost","root","root");
  mysql_select_db("FYP");
  $sql=mysql_query("select team_name, games_played, games_won,
  games_drawn, games_lost, goals_for, goals_against, goal_difference, 
  current_points from Team where team_name='Man Utd'");
  while($row=mysql_fetch_assoc($sql)) $output[]=$row;
  print(json_encode($output));
  mysql_close();
?>

that queries my db and returns all the rows matching the query etc etc, then encodes it into JSON, that looks like this:

[
    {
        "team_name": "Man City",
        "games_played": "24",
        "games_won": "18",
        "games_drawn": "3",
        "games_lost": "3",
        "goals_for": "63",
        "goals_against": "19",
        "goal_difference": "44",
        "current_points": "57"
    },
    {
        "team_name": "Man Utd",
        "games_played": "24",
        "games_won": "17",
        "games_drawn": "4",
        "games_lost": "3",
        "goals_for": "59",
        "goals_against": "24",
        "goal_difference": "35",
        "current_points": "55"
    }
]

which to my knowledge, is an array of JSON objects. However when i take this array to display as a list on my app, the tutorial i’m working off requires it to be a JSONObject rather than a JSONArray. I have tried to modify the code to take and array but i have had no luck, can anyone help? The android tut is: http://p-xr.com/android-tutorial-how-to-parse-read-json-data-into-a-android-listview/

The main part i’m having trouble with is this line of code:

    JSONArray  earthquakes = json.getJSONArray("earthquakes");

Obviously my JSON doesn’t have the element identifier like the sample does, and when i remove that line it doesn’t work. Any help would be brilliant, 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-05-29T21:38:46+00:00Added an answer on May 29, 2026 at 9:38 pm

    While your JSON result string is legit, it seems that the app (if modeled after the tutorial) is expecting an object as the outer enclosure, something like this:

    { "teams":
    [
        {
            "team_name": "Man City",
            "games_played": "24",
            "games_won": "18",
            "games_drawn": "3",
            "games_lost": "3",
            "goals_for": "63",
            "goals_against": "19",
            "goal_difference": "44",
            "current_points": "57"
        },
        {
            "team_name": "Man Utd",
            "games_played": "24",
            "games_won": "17",
            "games_drawn": "4",
            "games_lost": "3",
            "goals_for": "59",
            "goals_against": "24",
            "goal_difference": "35",
            "current_points": "55"
        }
    ]
    }
    

    This format (of utilizing an object as the outer enclosure) is actually pretty common among web services that return JSON/JSONP.

    Update
    Per this, the outer has to be an object. Using the recommended structure in my answer, your line would be:

    JSONArray  teams = json.getJSONArray("teams");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following PHP script : <?php header('Content-type: text/xml'); mysql_connect('localhost', 'root', 'root'); mysql_select_db('sportApp');
So i have this script: <?php $query = mysql_query( SELECT meetup AS text, id
Updated script with proper field names. Why isnt this working? <?php $con = mysql_connect(localhost,root,pass);
I have a php script that runs a mysql query, then loops the result,
I have an extremely simple script with PHP exec , calling mysql command: $dbhost
I have php script that creates a temporary watermark image for users that are
I have a PHP script that runs as a CGI program and the HTTP
I have a PHP script that needs to determine if it's been executed via
I have a PHP script that initialises an image gallery. It loops through all
I have a PHP script that can encode a PNG image to a Base64

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.