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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:05:55+00:00 2026-06-18T09:05:55+00:00

I have webservice written in PHP that reads from the local database and output

  • 0

I have webservice written in PHP that reads from the local database and output the result in JSON.

However, I am unable to output it into a JSONArray.

Here is the php script

<?php
$username = "root";
$password = "";
$hostname = "localhost"; 

$response=array();

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) 
or die("Unable to connect to MySQL");

//select a database to work with
$selected = mysql_select_db("test",$dbhandle) 
or die("Could not select test");

//execute the SQL query and return records
$result = mysql_query("SELECT name, country FROM android");

$response["infos"] = array();   

while ($row = mysql_fetch_assoc($result)) {

    $info = array();
$info["name"]=$row["name"];
$info["country"]=$row["country"];

    print(json_encode($info));

}

//close the connection
mysql_close($dbhandle);
?>

This is the output from the webservice

{"name":"develop","country":"mru"}{"name":"fufu","country":"tutu"}  {"name":"chikaka","country":"aceVentura"}

But I have been told that this is not in JSONArray.

What am I missing here?

Thank you

  • 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-18T09:05:56+00:00Added an answer on June 18, 2026 at 9:05 am

    In your example you’re echo’ing out multiple JSON strings because your output code is within a while loop. There should only be one output for the JSON string. The code below will give you a two dimensional array in JSON format.

    $info = array();
    
    while ($row = mysql_fetch_assoc($result)) 
    {
         $arr = array();
         $arr["name"] = $row["name"];
         $arr["country"] = $row["country"];
         $info[] = $arr;
    }
    
    echo json_encode($info);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a web service written in PHP, that returns JSON results. It works
I have written a webservice using the PHP SOAP classes. It has functions to
I have a .NET WebService (written in C#), that is supposed to serve people
I have a webservice written in Yii (php framework). I use C# and Visual
Below i have written code of a soap webservice in php with its client,It
I have an asp.net .asmx webservice written to handle requests from a third party
I have a PHP application that is written with Zend Framework. It uses Phing
I have a webservice, written in PHP, which I want to consume in a
I have problem with checking SoapFault response from writen in PHP Soap webservice. Responce
I have a webservice that is written in C# handling some validation of values.

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.