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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:22:28+00:00 2026-05-16T04:22:28+00:00

I am trying to get a multiple countdown system, event day and minutes being

  • 0

I am trying to get a multiple countdown system, event day and minutes being fetched from database. There can be many such events. After getting the event date, i pass this values to a javascript function which on client side runs for every 1 sec using the setTimout function. This works fine for one event. However for many events how do i achieve the same functionality. i.e i want to run the javascript function for each event.

I am getting some php variables from database. eg

while($row = mysql_fetch_array($query)){
$a = $row['day'];
$b = $row['minutes'];

}

Now i need to pass all this values inside a javascript function.
If there were only one event, i could directly pass the php values. But for multiple events i am confused as to what to do. I tried using a javascript function inside the while loop, but i get function not defined error, and that is obvious because php is run before javascrip. Any logic, or help appreciated.

Thanks

  • 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-16T04:22:29+00:00Added an answer on May 16, 2026 at 4:22 am

    In you PHP, first build your data array. It does not matter how you do it, but in the end, it may look something like :

    $data = array(
       array('day' => 1, 'minutes' => '15'),
       array('day' => 0, 'minutes' => '45'),
       array('day' => 15, 'minutes' => 52'),
       // etc.
    );
    

    Then (still with PHP, create a Javascript function like :

    var data = <?= json_encode($data) ?>;  // encode your PHP data into JSON notation
    var interval = setInterval(function() {
       for (var i=0; i<data.length; i++) {
          // do something with your data
          // data[i].day   ... data[i].minutes ... etc.
       };
    }, 1000);   // run every 1 sec
    

    Note that the more data you have, the slower setInterval will execute. Just remember that Javascript is slow compared to other languages. Also, setInterval is preferable over setTimeout in your case to avoid stacking up your calls in the long run, therefore you should not rely on setTimeout nor setInterval for a 1 second interval, but you should have a variable to calculate the exact time span between each calls.

    Something like;

    var last_time = new Date().getTime();
    

    then, inside your setInterval function, get how long the last function was called since last time (or for the first time, since page load)

    var cur_time = new Date().getTime();
    var timespan = (cur_time - last_time) / 1000; // millis > sec
    last_time = cur_time; // update last_time
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get data from multiple XML feeds and copy that data to
I have a tricky situation in trying to get information from multiple queries into
I'm trying get values from a GridView using the following code: foreach (GridViewRow row
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
Im trying to get a completly data copy from a gridview, itryed clone(), tryed
I have a question about the JFileChooser in Swing. I'm trying to get multiple
I am trying to get a multiple upload library working for my Codeigniter based
Trying to get my css / C# functions to look like this: body {
Trying to get an ASP application deployed; it worked for a while but then
Whilst trying to get our app working in Firefox (I'm a big proponent of

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.