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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:44:41+00:00 2026-05-29T08:44:41+00:00

I have an AJAX script that receives a string from a mySQL query returned

  • 0

I have an AJAX script that receives a string from a mySQL query returned by PHP.
This string is then parsed and put into an array in Jquery and the results are printed to the screen using .html()

The length of this array varies from 0 items to many, how would I count the items in the array then loop through and print them to the screen.

Here is my UPDATED code per the advice below, though I am still not sure if the for loop goes inside the .html() function or outside?

UPDATED CODE TO INCLUDE .each()

UPDATE 2: Replace (this) in the .html() function with the element I want the text written in and it is working partially, issue is now it is only printing the last item in the array?

UPDATE 3: Seems you can only have a single .html() function run, for instance if I add another .html() statement under the one that is returning the last item in my array it will only now echo on the screen the test value.

$("#n_detail").html(partsArray[index]+"<br />").addClass('jText').fadeTo(900,1);
$("#n_detail").html("Test").addClass('jText').fadeTo(900,1);    

It will only print “Test”, not the last item in the array like it was previously?

<script type="text/javascript">
       $(document).ready(function() {
        $("#primary").change(function()
            {                                
             $.post("lib/ajax_load_job_detail.php",{ _primaryid_n:$(this).val() } ,function(data)
            {
            var string = data;
            var partsArray = string.split('|');
               $("#n_detail").fadeTo(200,0.1,function() //start fading the messagebox
               {
                 $.each(partsArray, function(index) {
                        $("#n_detail").html(partsArray[index]+"<br />").addClass('jText').fadeTo(900,1);
                    });     
                });
              });
            });
           });

Sample value of array partsArray[0]12/12/2005, partsArray[1]This is a sample note from December, 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-05-29T08:44:41+00:00Added an answer on May 29, 2026 at 8:44 am

    If you are iterating through an array then you could use the jQuery function each().

    Here’s a link to the docs: http://api.jquery.com/jQuery.each/

    Here’s a sample from the docs using your array:

    $.each(partsArray, function(index, value) { 
      alert(index + ': ' + value); 
    });
    

    EDIT – based on a comment the OP added to another answer, here’s a better example using the OPs code:

    $.each(partsArray, function(index, value) { 
      value.addClass('jText').fadeTo(900,1);
    });
    

    EDIT 2 – you need the part of the code that is per element of the arry inside the loop and based on your edits I think it should look like this:

    $.each(partsArray, function(index) {
        $(this).append(partsArray[index]+"br />").addClass('jText').fadeTo(900,1);
    }
    

    Cheers,

    James

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey guys I have an ajax jquery function that receives data from a php
I have developed a script that receives json data from a php script using
I have a php file that receives data from mySQL table. The mySQL table
I have a script that retrieves objects from a remote server through an Ajax
I have a jquery-ajax function that sends data to a php script and the
I have an AJAX script that post data in one of my PHP file:
I have this ajax_update script that updates file.php every 60 seconds.. Now file.php outputs
I have this ajax_update script that updates file.php every 60 seconds.. Now file.php outputs
At the minute I have a page with an AJAX script that searches a
I have a web service site that is restful enabled, so other websites/ajax script

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.