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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:57:09+00:00 2026-06-04T23:57:09+00:00

I tried to retrieve multiple rows of JSON data and display it but im

  • 0

I tried to retrieve multiple rows of JSON data and display it but im not able to retrieve all the rows,im only getting the top(first) row of the database table.And im confused about how can i put the retrieved JSON data into some sort of array and access the individual rows?

I have provided the code relevant to the problem.
Yes i have done enough research before posting this question.I actually found one question which was some what similar to mine but nobody has answered it so i’m making this post.

Thank You

Below is the code from my Freebies.java class where i’m trying to retrieve JSONdata by calling getAllFreebies function from UserFunctions.java class

UserFunctions uf = new UserFunctions();
JSONObject json = uf.getAllFreebies();
System.out.println(json);

Below is the code of the function getAllFreebies() in the class UserFunctions.java

public JSONObject getAllFreebies(){
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("tag", getAllFreebies_tag));
    JSONObject json = jsonParser.getJSONFromUrl(getAllFreebiesURL,params);
    return json;
}

Below is the code from index.php where im calling getFreebies() function from DB_Function.php file

else if($tag = 'getAllFreebies'){
                    $getAllFreebies = $db->getFreebies($username,$catagory,$subcatagory,$title,$condition,$description,$address,$city,$state,$country,$zipcode,$posted_on);
                    if($getAllFreebies)
                    {
            $response["success"] = 1;
            $response["getAllFreebies"]["username"] = $getAllFreebies["username"];
            $response["getAllFreebies"]["catagory"] = $getAllFreebies["catagory"];
            $response["getAllFreebies"]["subcatagory"] = $getAllFreebies["subcatagory"];
            $response["getAllFreebies"]["title"] = $getAllFreebies["title"];
            $response["getAllFreebies"]["item_condition"] = $getAllFreebies["item_condition"];
            $response["getAllFreebies"]["description"] = $getAllFreebies["description"];
            $response["getAllFreebies"]["address"] = $getAllFreebies["address"];
            $response["getAllFreebies"]["city"] = $getAllFreebies["city"];
            $response["getAllFreebies"]["state"] = $getAllFreebies["state"];
            $response["getAllFreebies"]["country"] = $getAllFreebies["country"];
            $response["getAllFreebies"]["zipcode"] = $getAllFreebies["zipcode"];
            $response["getAllFreebies"]["posted_on"] = $getAllFreebies["posted_on"];
            echo json_encode($response);
                        }else {
                            $response["error"] =1;
            $response["error_msg"] = "Error in getAllFreebies";
            echo json_encode($response);

                            }
                    }// end of getAllFreebies tag

Below is the code of my getFreebies() function of DB_function.php which is responsible for performing queries on MySQL database.

public function getFreebies(){
$result = mysql_query("SELECT * FROM freebie") or die(mysql_error());
return mysql_fetch_array($result);
}

Below is the logcat:

05-30 00:13:23.960: E/JSON(318): {"tag":"getAllFreebies","success":1,"error":0,"getAllFreebies":{"username":"viking","catagory":"Art","subcatagory":"Potrait","title":"Potrait","item_condition":"Good","description":"potarit","address":"Blah St","city":"lalaland","state":"NA","country":"NA","zipcode":"blah","posted_on":"2012-05-27"}}
  • 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-04T23:57:11+00:00Added an answer on June 4, 2026 at 11:57 pm

    mysql_fetch_array() only returns a single row of the query result set as an array. It does not fetch ALL of the rows. Since you’re returning the results of the fetch from your getFreebies method, instead of the result handle itself, it is impossible for the calling code to get any other results from the query, other than the one row you’ve fetched.

    As such, you should have:

    public function getFreebies() {
       $result = ...
       return($result);
    }
    

    and

    $getAllFreebies = $db->getFreebies(...);
    $data = array();
    while($row = mysql_fetch_assoc($getAllFreebies)) {
       $data[] = array(
          .... your variable assignments here ...
       );
    }
    echo json_encod($data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple forms with id=#REQUESTFORM. To retrieve the correct information when sending data,
Trying not to select same connection multiple times I have tried to use charindex()
How to programmatically retrieve configuration of the specific rule? I tried $settings = rules_config_load('RULE_NAME');
I have tried this example http://www.bennadel.com/blog/1056-ColdFusion-CFPOP-My-First-Look.htm , but it retrieve emails from POP server.
Tried a bunch of things but I can't get it to work consistently amid
tried to find the answer by googling and in MSDN but with no luck.
Tried examples from 'php.net' but don't understand what's the problem. Any suggestions? <?php $_SESSION['test']
Tried to install some program, it gives above message requiring 1.1.4322. BUT as the
tried to research on that but sometimes I seem to lack some googling skills...
I need, in a single call, to retrieve multiple images in a facebook stream.

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.