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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:03:16+00:00 2026-06-13T07:03:16+00:00

This is my first post and I’m not really a developer (more an enthusiastic

  • 0

This is my first post and I’m not really a developer (more an enthusiastic tinkerer).

I’m trying to create some rotating text (the visible item is switched with JQuery every 10 seconds or so) on a website based upon information taken from a MySQL DB.

At the moment I create the HTML directly from the MySQL results before applying the rotation JQuery function after page load is complete. The problem I have is that the creation/rendering of the HTML up front is slowing down the page load time with other elements backing up behind the HTML that is created.

This occurs even though the Javascript isn’t run until the document is loaded (I also know that the DB query takes a couple of milliseconds.) I’ve isolated the issue by forcing the query to return 1 row, 10 rows, all rows etc. noting the slow down in page load time with each change.

The rendered HTML looks something like this:

<div id="container">
    <div class="item">
        <span class="field1">row 1 field 1</span>
        <span class="field2">row 1 field 2</span>
    </div>
    <div class="item">
        <span class="field1">row 2 field 1</span>
        <span class="field2">row 2 field 2</span>
    </div>
    <div class="item">
        <span class="field1">row 3 field 1</span>
        <span class="field2">row 3 field 2</span>
    </div>
    ...
</div>

The solution I have (happy for alternative suggestions) is to render the first row up-front and then create the rest after the page has loaded (there’s a 10 second delay in the rotation which should be sufficient time).

The other benefit to this is that the additional content doesn’t create a mess of my page before the JQuery element starts the rotation process (I can get around this, but two birds, one stone etc.)

I found a post on this forum to create a JSON array from the MySQL data:

<?php
$result=mysql_query("SELECT * FROM my_table");

$my_result_array=array();
while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
    array_push($my_result_array,$row);
    }

$json_array = json_encode($my_result_array);
?>

At this point, I’m now stuck. I’ve found some more useful input on this forum for creating the necessary HTML objects after loading:

var t = $.template('<div class="item"><span class="field1">${field1}</span><span class="field2">${field2}</span></div>');

$(selector).append( t , {
 dataPart1: jsonObj.field1,
 dataPart2: jsonObj.field2
});

The bit that I’m not clear on (I know very little about Javascript and JSON) is how I get from my array text as created in the PHP, to this last part which has an object that it can iterate through.

All suggestions are hugely appreciated!

  • 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-13T07:03:17+00:00Added an answer on June 13, 2026 at 7:03 am

    You need to do an AJAX post from javascript:

    $.post('file.php', {},
          function(data) {
                //the data variable holds the json returned from PHP
                //parse it
            var jsonObj= $.parseJSON(data);
                //then use it like an object
                $(selector).append( t , {
                dataPart1: jsonObj.field1,
                dataPart2: jsonObj.field2
              });
    });
    

    Server-side you need to echo your json variable:

    file.php

    $my_result_array=array();
    while($row = mysql_fetch_array($result,MYSQL_ASSOC)){
        array_push($my_result_array,$row);
        }
    
    $json_array = json_encode($my_result_array);
    echo $jsonArray;
    ?>
    

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

Sidebar

Related Questions

This is my first post here so go easy. I am trying to build
this is my first post here. I need create a feed like facebook with
this is my first post. I am selecting some fields from a database which
This is my first post here after many visits. Hello! I am trying to
this is my first post here. First off, some background, I'm new to C#
I'm trying to render the list of blog posts in this layout: [first post
this is my first post so please show some understanding. I have some java
This is my first post so I hope I am not violating any rules.
This is my first post here and I wanted to get some input from
This is my first post on StackOverflow, so please be gentle... I have some

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.