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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:43:03+00:00 2026-06-01T07:43:03+00:00

i am working with JSON to send data to and from my server ,

  • 0

i am working with JSON to send data to and from my server , but normally i work with sending one data at a time , now i want to :
retrieve all the rows from a table (mysql database) –> php put it in a JSON array + callback —> javascript retrives it and display it out by looping through the data.

Here’s my javascript(jQuery):

$.getJSON(domain_path + 'generate.php?table=' +  tbname + '&callback=?', function(data) {
});

As you can see this has table= the table name. which is for php to know which table to extract the data from.

But for the php part im not sure what to use to produce a JSONP array.

<?php
//connects to database
  include 'connect.php';

$tbname = mysql_real_escape_string($_GET['table']);
$callback = $_GET['callback'];

//some mysql commands
//after mysql commands
//i would use this to output data but this is only for one line of data.

    $output = array('error'=>'0');
    $out_string =  json_encode($output);
    echo $callback.'('.$out_string.');';    

?>

Mysql table structure:
Table name : users
name , link , email

How can i get all the rows from users table which contians their name , link and email and out it into a JSON array.
And how would i display it out using javascript(jquery)?
Is it using the for function in javascript

  • 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-01T07:43:04+00:00Added an answer on June 1, 2026 at 7:43 am

    Print out the JSON array in PHP:

    $query = mysql_query("SELECT * FROM ".$tbname."");
    $rows = array();
    while($r = mysql_fetch_assoc($query)) {
       $rows[] = $r;
    }
    print json_encode($rows);
    

    Catch and loop over result in jQuery:

        $.getJSON(domain_path + 'generate.php?table=' +  tbname + '&callback=?', function(data) {
             $.each(data, function() {
               $.each(this, function(k, v) {
               /// do stuff
               });
             });
        });
    

    First each loop goes over your rows/objects; second loop goes over your attributes/columns.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm calling 2 JS functions(Ajax) each of which are returning data from the server.But
I now have a working JSON formatted file from my PHP scripts. The next
i use json_encode to send back data from php to jquery through ajax. and
Previously i wrote an app that used reflection to serialize data from json to
I have a data Store that gets it's information from a JSON api on
Hi i need to post some data to a web server from windows phone
Some information - I'm creating an autocomplete which gets the data from a json
I am trying to retrieve some data from a database using jQuery's $.getJSON method
I'm working on a web based application which uses a JSON over HTTP based
Working on a somewhat complex page for configuring customers at work. The setup is

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.