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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:17:00+00:00 2026-06-13T07:17:00+00:00

I am trying to retrieve data with JSON from my database and parse them

  • 0

I am trying to retrieve data with JSON from my database and parse them in a table.

Currently I retrieve it like this:

xmlhttp = new XMLHttpRequest()

xmlhttp.onreadystatechange = function () {
    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
        var jsontext = xmlhttp.responseText;
        var json = JSON.parse(jsontext);

        console.log(json.service)

    }
}

xmlhttp.open("GET", "mysql.php?p=getservice" + "&carid=" + "KYF111", true);
xmlhttp.send();

This will give me one result, no matter how many rows I have with id ‘term’.

My mysql.php file looks like this:

case 'getservice':

$q = mysql_real_escape_string($_GET['q']);
$carid = stripslashes($_GET['carid']);
$query = "SELECT * FROM Service WHERE carid = '".$carid."'";

$result = mysql_query($query);

$json = array();
while ($row = mysql_fetch_array($result)) {

    $json['carid'] = $row['carid'];
    $json['service'] = $row['service'];
    $json['date'] = $row['date'];
    $json['nextdate'] = $row['nextdate'];
    $json['kilometers'] = $row['kilometers'];
    $json['servicedby'] = $row['servicedby'];
    $json['invoice'] = $row['invoice'];
    $json['cost'] = $row['cost'];
    $json['remarks'] = $row['remarks'];

}
print json_encode($json);

mysql_close();

break;

This is how my database looks like:

enter image description here

so the term would be the cardid, and I want all the values from the rows which contains carid the term. Then each value on a single row gets between a . Something like this:

<tbody>
    <tr>
        <td>Tyre</td>
        <td>10-10-2012</td>
        <td>31-10-2012</td>
        <td></td>
        <td>George</td>
        <td>8951235</td>
        <td>0</td>
        <td>Lorem Ipsum</td>
    </tr>
    <tr>
        <td>Lights</td>
        <td>17-10-2012</td>
        <td>23-10-2012</td>
        <td></td>
        <td>Antony</td>
        <td>4367234</td>
        <td>0</td>
        <td>Lorem Ipsum</td>
    </tr>
</tbody>
  • 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-13T07:17:01+00:00Added an answer on June 13, 2026 at 7:17 am

    Try like this:

        $temp=0;
        $json = array();
            while ($row = mysql_fetch_array($result)) {
    
                $json[$temp]['carid'] = $row['carid'];
                $json[$temp]['service'] = $row['service'];
                $json[$temp]['date'] = $row['date'];
                $json[$temp]['nextdate'] = $row['nextdate'];
                $json[$temp]['kilometers'] = $row['kilometers'];
                $json[$temp]['servicedby'] = $row['servicedby'];
                $json[$temp]['invoice'] = $row['invoice'];
                $json[$temp]['cost'] = $row['cost'];
                $json[$temp]['remarks'] = $row['remarks'];
        $temp++;
            }
    print json_encode($json);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to retrieve data from a JSON object that looks like this: stdClass
I'm trying to save the data retrieved from the database into a .json. This
I'm trying to retrieve some data from a JSON response, but this doesn't seem
Iam trying to retrieve data from mysql database into stylesheet.php but it is not
I’m trying to retrieve data from an entity and populate a viewModel property like
I am trying to retrieve data into an xml tag from the database using
I am trying to retrieve CLOB data from our Oracle database. the code is
I'm trying to retrieve hierarchical data from a table but am failing to do
I'm trying to retrieve record data from an MS-Access database and store it into
I am trying to retrieve JSON data from an external text file using a

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.