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

  • Home
  • SEARCH
  • 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 6175327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:54:22+00:00 2026-05-23T23:54:22+00:00

I am using ajax to pull some data from a PHP script I created.

  • 0

I am using ajax to pull some data from a PHP script I created. The PHP script queries the database for user information and comment information. There will be a lot of comments and I am trying to figure out how to return 3 records (LIMIT 3) – this is what I have:

foreach($results->fetch_assoc() as $key => $db_value) {
    //$array[$key] = $db_value;
    print_r($results->fetch_assoc());
}

$results->fetch_assoc() returns a single record set. I was messing around and couldn’t figure it out.

What I am trying to do is have 3 arrays returned to the HTML doc via json_encode so that I can read it and display it. Can anyone help?

  • 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-23T23:54:22+00:00Added an answer on May 23, 2026 at 11:54 pm
    $data = array();
    
    while ($row = $results->fetch_assoc()) {
       $data[] = $row; // stuff new row onto end of array
    }
    
    echo json_encode($data);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok, So I'm using AJAX to pull some information from my MYSQL database and
Heh, I'm using jQuery AJAX Call to pull data from a self hosted webservice
Im using Ajax to send values to a PHP script which writes some value
I am attempting to pull some information from my tnsnames file using regex. I
Using AJAX to pull data from a dynamically generated XML using .NET. Using simple
How can javascript pass data, for example from an HTML table, without using AJAX?
I have some forms that communicate with server using AJAX for real reasons: cascade
I'm trying to learn some basic ajax using Django. My simple project is an
I'm using the jQuery .load() function to pull in data to populate a div
I am using getJson to pull in some info onto the page $('#request_song').autocomplete({ serviceUrl:

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.