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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:29:34+00:00 2026-06-17T06:29:34+00:00

I am working on a jQuery script that retrieves a PHP array from MySQL

  • 0

I am working on a jQuery script that retrieves a PHP array from MySQL database and returns it as a JSON object.
This all works correctly and I can output the raw JSON object, including the key.

The issue I am having is the way I am outputting it, which I currently do using jQuery’s $.each.

Example: (Not the full script, just what is needed)

                if(data){
                $.each(data, function(key, data) {
                $('#div').append(  key + ' : '  + data  );

                });

        }

    } , 'json')

So at the moment the output is like so: Example

     Name: Tom Age: 20 Gender: Male

However I don’t want all results of the array to be returned, which is what $.each is doing.
I want to manually output different parts of the array, where and when I want.

I tried something like this so that I could just get the array result that has the Key of “name” but it did not work (one of my array keys is name):

    $('#div').append(  key + ' : '  + data['name']  );

Any suggestions?

EDIT: Making it a bit more clear:

Rather than looping through and outputting the entire array I want to output only select parts: e.g;

data.name
data.age

Those for example will only output the 2 arrays with the name and age key, even if the array has 10 other results.

Array we are working with is like so, only 1 result, but with multiple values.:

    {Name: 'Tom' Age: 20 Gender: 'Male'}
  • 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-17T06:29:36+00:00Added an answer on June 17, 2026 at 6:29 am

    What about:

    $.each(data, function(key, data) {
        $('#div #span-'+key).html(data);
    });
    

    So if you have the keys name, age, gender, you need 3 spans with the ID: #span-name, #span-age, #span-gender and they will be filled in with the data. If you only need name and age, just delete your #span-gender span and it won’t show.

    Your html will be something like:

    <div id="div">
        <span id="span-name"></span>
        <span id="span-age"></span>
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a jQuery script that shows a random slogan from an array
I'm working on this page for a photographer. I wrote a jQuery script that
Recently, using javascript(jQuery to be specific) I was working on a script that retrieves
I have been working on a JQuery script that posts JSON to my asp.net
I'm currently working on a jQuery script that will translate the site's text into
Okay I'm working in jQuery mobile, and I just put in a PHP script
I used this script to create a jQuery accordion. Check out the working jsFiddle
I have a jquery script that searches a php file that produces an XML
I have a jquery script that is working fine except being able to send
I have a jQuery script that is working well for the most part. I

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.