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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:58:44+00:00 2026-06-07T05:58:44+00:00

My code $sql=SELECT * FROM `room_lists`; $sqlquery = mysql_query($sql); while($result = mysql_fetch_array($sqlquery)){ $toDay =

  • 0

My code

$sql="SELECT * FROM `room_lists`";
$sqlquery = mysql_query($sql);
while($result = mysql_fetch_array($sqlquery)){

$toDay = strtotime($result['timeStop']); 
//echo $toDay;

?>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=tis620" />
<script type="text/javascript" src="core/jquery-latest.js"></script>
<title>test</title>
<script type="text/javascript">

function countDown(times){
    var toDay=Math.round(new Date().getTime()/1000); 
    var difTime=times-toDay;
    var day=0,hours=0,minutes=0,seconds=0;
    if(difTime>0){
    day=Math.floor(difTime/84600);
    hours=Math.floor((difTime/3600))%24;
    minutes=Math.floor(difTime/60)%60;
    seconds=Math.floor(difTime)%60; 
    countDown_onLoad();
    }
    else{
        alert('asd');   //time out
    }
    $('.show').html(day+' Day '+hours+' Hour '+minutes+' Min '+seconds+' Sec ');
}
function countDown_onLoad(){
    setTimeout("countDown(<?=$toDay ?>);",1000);
}
$(document).ready(function() {
countDown_onLoad();
});

</script>

</head>

<body>
<div class="show"></div>

</body>


</html>
<? } ?>

Hello, I am a newbie using javascript. I have created countdown timer to use like auction website with js function that call from database(timestamp type) with php query, if the result is 1 row, it works fine but if more than 1 the result are all the same as last row in database. How can I fix this?

This is my output

0 Day 1 Hour 41 Min 25 Sec
0 Day 1 Hour 41 Min 25 Sec
  • 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-07T05:58:45+00:00Added an answer on June 7, 2026 at 5:58 am

    You appear to be outputting an entire HTML document (less the opening <html> tag and <!doctype>) for every counter.

    The core problem is that you are using $(".show").html(...) to output the counter, which is essentially telling it to put that content in every .show element. The net result is that they all show the same thing: whatever the last counter is at.

    Your approach is almost unsalvageable, but here is my best attempt:

    <!DOCTYPE html>
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=tis620" />  
        <script type="text/javascript" src="core/jquery-latest.js"></script>  
        <title>test</title>  
        <script type="text/javascript">
          function countDown(){  
              var toDay=Math.round(new Date().getTime()/1000);   
              $(".show").each(function() {
                  var elm = $(this);
                  var difTime=this.timestamp-toDay;  
                  var day=0,hours=0,minutes=0,seconds=0;  
                  if(difTime>0){  
                      day=Math.floor(difTime/84600);  
                      hours=Math.floor((difTime/3600))%24;  
                      minutes=Math.floor(difTime/60)%60;  
                      seconds=Math.floor(difTime)%60;   
                  }  
                  else{  
                      alert('asd');   //time out  
                      elm.removeClass("show");
                  }  
                  elm.html(day+' Day '+hours+' Hour '+minutes+' Min '+seconds+' Sec ');  
              });
          }  
          function countDown_onLoad(){  
              $(".show").each(function() {
                  this.timestamp = parseInt(this.firstChild.nodeValue,10);
              });
              setInterval(countDown,1000);
          }  
          $(document).ready(function() {  
              countDown_onLoad();  
          });  
        </script>  
    </head>  
    <body>
        <?php
          $sql="SELECT * FROM `room_lists`";   
          $sqlquery = mysql_query($sql);   
          while($result = mysql_fetch_array($sqlquery)){   
              $toDay = strtotime($result['timeStop']);  
              echo "<div class=\"show\">".$toDay."</div>";
          }
        ?>
    </body>
    </html>
    

    Please note that I do not use jQuery. I am only using it here because you were already using it. With that in mind I may have incorrectly used .each(). Please let me know if you encounter any errors and I will try to fix them.

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

Sidebar

Related Questions

I have the code below: string SQL = select * from + TableName; using
I normally use the following code in SQL Server: IF EXISTS (SELECT * FROM
I use this code to select password field from the sql server 2012 db,
i have this recursive code <ul> <% sql=SELECT * FROM cats ORDER BY orderid
Code: var result = db.rows.Take(30).ToList().Select(a => AMethod(a)); db.rows.Take(30) is Linq-To-SQL I am using ToList()
This is my code: string SQL = SELECT email FROM members WHERE subscribe=true; string
Consider the following code: Dim sql = SELECT * FROM MyTable WHERE value1 =
The following piece of code: Session(SQL) = SELECT * FROM tbl_policyLinktoClient where aut_id =
IF I have a code like $vals = 50,60,40; IN SQL SELECT * FROM
This is my SQL code SELECT p.plant_name, sum(data.value_1) totalvalue_1 FROM (SELECT DISTINCT date_format(date, '%Y-%m')

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.