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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:36:02+00:00 2026-06-14T19:36:02+00:00

I have an index.php file that I would like to run getdata.php every 5

  • 0

I have an index.php file that I would like to run getdata.php every 5 seconds.

getdata.php returns multiple variables that need to be displayed in various places in index.php.

I’ve been trying to use the jQuery .load() function with no luck.
It’s refreshing the 12 <div> elements in various places on the index.php, but it’s not re-running the getdata.php file that should get the newest data.

But If I hit the browser refresh button, the data is refreshed.

getdata.php returns about 15 variables.

Here is some sample code:

<script>
    var refreshId = setInterval(function()
    {
         $('#Hidden_Data').load('GetData.php'); // Shouldn´t this return $variables
         $('#Show_Data_001').fadeOut("slow").fadeIn("slow");
         $('#Show_Data_002').fadeOut("slow").fadeIn("slow");
         $('#Show_Data_003').fadeOut("slow").fadeIn("slow");
         $('#...').fadeOut("slow").fadeIn("slow");
    }, 5000); // Data refreshed every 5 seconds
    */
</script>

Here’s an example of GetData.php:

$query = "SELECT column1, COUNT(column2) AS variable FROM table GROUP BY column";
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){
$column1 = $row['column1 '];
$variable = $row['variable '];

if($column1 == "Text1") { $variable1 = $variable; }
    elseif($column1 == "Text2") { $variable2 = $variable; }
              ... continues to variable 15 ...
}

Then further down the page the HTML elements display the data:

<div id="Hidden_Data"></div>
<div id="Show_Data_001"><?php echo $variable1; ?></div>
<div id="Show_Data_002"><?php echo $variable2; ?></div>
<div id="Show_Data_003"><?php echo $variable3; ?></div>
...

I tried using the data parameter as suggested here:
https://stackoverflow.com/a/8480059/498596

But I couldn’t fully understand how to load all the variables every 5 seconds and call them on the index page.

Today the GetData.php page just returns $variable1 = X; $variable2 = Y and so on.

UPDATE
For some reason the jQuery is not loading the GatData.php file and refreshing the variables.

I tried adding to “Hidden_Data” to the include('GetData.php') and then the variables are readable on the page.

If I remove this part, the page displays “variable not set” warning that suggesting that the jQuery is not loading the GetData.php script into the Hidden_Data <div>.

  • 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-14T19:36:03+00:00Added an answer on June 14, 2026 at 7:36 pm

    Try

     <script>
            var refreshId = setInterval(function()
            {
                 $('#Hidden_Data').load('GetData.php', function() { // Shouldn´t this return $variables
                     $('#Show_Data_001').fadeOut("slow").fadeIn("slow");
                     $('#Show_Data_002').fadeOut("slow").fadeIn("slow");
                     $('#Show_Data_003').fadeOut("slow").fadeIn("slow");
                     $('#...').fadeOut("slow").fadeIn("slow"); });
            }, 5000); // Data refreshed every 5 seconds
            */
        </script>
    

    Above is assuming, that your code returns snippet of HTML elements (Show_Data_XXX), but now that you’ve clarified your question above wont help you alone…

    What you need to do is either in your php send back new value elements or send back your results as data and update existing elements.

    Put your elements into a php Array and then send it back
    data.php after sql call

    $results = Array();
    while($row = mysql_fetch_array($result)){
       $column1 = $row['column1 ']; // change Text1 in db to Show_Data_001 in html or vice versa
       $variable = $row['variable '];
       $results[$column1] = $variable;
    }
    
    echo json_encode($results);
    

    in your javascript something like this…

    $.getJSON('GetData.php',function(data) {
    $.each(data, function(key, val) {
        $('#'+key).text(val);
      });
    });
    

    I didn’t put the fadeOut and fadeIn into the example, because it complicates it a bit. You could do fadeOut to all those elements before calling getJSON and the fadeIn as the results pouring in. Hope this helps

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

Sidebar

Related Questions

I have a directory named dollars that contains a file index.php . I would
I have a index.php file that will include several external files: content/templates/id1/template.php content/templates/id2/template.php content/templates/id3/template.php
I have a PHP script (index.php) that includes an index.html file in a sub-directory
I have a file system structure with symlinks, something like this: folder123 index.php config.php
I have a ZendFramework project that I would like to run inside a subdirectory.
I have an index.php that updates every second user sessions: [Index.php (before )] <script
I have a index.php file which loads (require) 2 different files based on a
I have an index.php file which has 2 included files require(stats.php); require(stats_encry.php); stats.php which
If I have three files index.php file.php and fns.php First example (it works): index.php
I'm trying to develop a Facebook application, and I have uploaded my index.php file,

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.