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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:35:49+00:00 2026-05-20T15:35:49+00:00

I am using json_encode to create a JSON object from an array. They array

  • 0

I am using json_encode to create a JSON object from an array. They array is a couple hundred elements long, but json_encode appears to only give back the first element of the array.

Is this a limitation of json_decode, or am I using the wrong syntax to read the JSON object?

A little code:
I create the array in PHP:

$getarrayforjson = mysql_fetch_array($result);

And in the javascript, I made it a variable:

var my_array = <?php echo json_encode($getarrayforjson); ?>

Typing ‘my_array’ in the console gives me a nice JSON-looking response, but only for the first element.

When I use the JSON in the code, like my_array.title, or my_array[4], I always get the same result.

I think my syntax is wrong, but am not sure how to fix it. I’m new to using json_encode.

  • 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-20T15:35:50+00:00Added an answer on May 20, 2026 at 3:35 pm
    $getarrayforjson = mysql_fetch_array($result);
    

    That is only one result. Try this:

    <?php
    while( $row = mysql_fetch_array( $result ) ) {
        $json[] = $row;
    }
    echo json_encode( $json );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using dict to create a json object but I am having some
I'm using the combination of json_encode (PHP) and JSON.parser (Javascript from json.org) for passing
I have created a JSON object in php using json_encode and am attempting to
I create a huge JSON-Object and save it in my database. But when I
Background: Using jQuery 1.7 client side PHP server side Using json responses with json_encode
This piece of valid json (it has been generated using php's json_encode): {html:form is
I'm using Json.Net to handle the deserialzing of the response of API calls from
I'm using the SQLAlchemy recipe here to magically JSON encode/decode a column from the
I have saved out an object using JSON.encode to a text file, is it
Im trying to output or create json using wordpress posts data coupled with meta_key

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.