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

The Archive Base Latest Questions

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

From a database query I’m getting one record returned with fields/values and putting it

  • 0

From a database query I’m getting one record returned with fields/values and putting it into an array:

$arr = array();
while ($rowSearchZipCode = mysqli_fetch_array($resultSearchZipCode, MYSQLI_ASSOC)) {
    $arr[] = $rowSearchZipCode;
}

I’m sending this back to a jQuery ajax call via an echo from the php script:

echo print_r($arr);

Displaying the array in an alert box in the success parameter of $.ajax shows me that I’m getting a multidimensional array that looks like this:

Array
(
[0] => Array
    (
        [id] => 55
        [branchName] => SBN - Some Branch Name
        [branchAddress1] => 1234 Elm St.
        [branchAddress2] => Suite 000
        [branchAddressCity] => Anywhere
        [branchAddressState] => CA
        [branchAddressZip] => 55000
        [branchAddressPhone] => 555-555-5555
        [branchAddressFax] => 555-555-4444
    )

)
1

Question 1: Am I building the array correctly in the while loop?

Question 2: In the $.ajax call how do I get the field/value pairs from the array so that I can output them to HTML tags, etc?

  • 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-17T15:13:27+00:00Added an answer on June 17, 2026 at 3:13 pm

    PHP side :

    • don’t forget to send the correct JSON header with:

      header('Content-Type: application/json');
      
    • and use json_encode to encode your array before echoing it:

      echo json_encode($myarray);
      

    Client side use :

    $.ajax({
        url: '<url>',
        dataType: "json", //optionnal if you correctly set the header
        success: function(data){
            for (var i in data) {
                console.log(data[i]); //data[i] are JS object
            }
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array built from a database query. Based on the values posuition
I want to order values from database query by date but I want also
I'm using my sql to get unique values from database My query looks as
I have a strongly-typed DataTable returned in a strongly-typed DataSet from a database query.
i'm getting a very strange result from my database query, i was hoping someone
what i am attempting to build is an array from a database query in
I have two arrays (records returned from a database query) that I'm merging. I
I have the following data being returned from my database query: +---------------+-----------+------------------+--------------+-------+ | district_name
I have a hash of values from a database query: a1 = {:a =>
I'm looking for a way to return an array from the database query, but

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.