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 results from a MySQL database (for invoices) that includes multiple
I am trying to get jquery validate to work on multiple fields. Reason being
Following on from an earlier question I'm trying to get multiple (widgets or in
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 am trying to get multiple values from a multiple select option box in
I am trying to get data from multiple tables at once. In my old
I'm trying to grab multiple rows via these lines from the MySQL database: $msg_sql
Here's an ASPX code snippet from when I was trying to get multiple values
I'm trying to get a drop down list to display multiple columns from a

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.