Javascript countdown in a PHP while loop -


edit: solved.

the 'items' table has multiple tuples, , each of them used have name,image,price,description , bid system (a text field , submit) printed on webpage. worked wondefully until decided wanted each of them have countdown timer too. timer works way: every time there's new bid on item, item's timer resets x minutes/seconds/whatever. when insert include.php original code, first instance processed.

i know due php , javascript not 'running' @ same time, wonder how can fix javascript have problem sorted out.

the classic echo solution doesn't work.

this while loop:

while ($row = @ mysql_fetch_array($results)) {  print "<div id='item'>". "<p>".$row["name"]."</p>". "<img src= uploads/".$row["image"].">". "<p>&euro;".$row["final_price"]."</p>". "<p>".$row["description"]."</p>". "<form method = 'get' action = 'sum.php'>". "<input type = 'hidden' name = 'itid' value = ".$row["id"].">". "<tr><td><input type = 'number' name = 'bid' required = 'required'></td></tr><br>". "<tr><td><input type = 'submit' value = 'bid'></td></tr>". "</form>"; include('cntdwn.php'); print "</div>"; } 

solved setting cntdwn.php way:

<?php ${"query1".$row['id']}= "select time_up items id = '" .$row["id"]."'"; ${"results".$row['id']} = mysql_query (${"query1".$row['id']}); while (${"row".$row['id']} = @ mysql_fetch_array(${"results".$row['id']})) {${"rez".$row['id']} = ${"row".$row['id']}['time_up'];} //$date = 'january 22 2017 09:10:00 pm cet'; ${"exp_date".$row['id']} = strtotime(${"rez".$row['id']}); ${"now".$row['id']} = time();  if (${"now".$row['id']} < ${"exp_date".$row['id']}) { ?> <script> // count down milliseconds = server_end - server_now = client_end - client_now var server_end<?php echo $row['id']; ?> = <?php echo ${"exp_date".$row['id']}; ?> * 1000; var server_now<?php echo $row['id']; ?> = <?php echo time(); ?> * 1000; var client_now<?php echo $row['id']; ?> = new date().gettime(); var end<?php echo $row['id']; ?> = server_end<?php echo $row['id']; ?> - server_now<?php echo $row['id']; ?> + client_now<?php echo $row['id']; ?>; // real end time  var _second<?php echo $row['id']; ?> = 1000; var _minute<?php echo $row['id']; ?> = _second<?php echo $row['id']; ?> * 60; var _hour<?php echo $row['id']; ?> = _minute<?php echo $row['id']; ?> * 60; var _day<?php echo $row['id']; ?> = _hour<?php echo $row['id']; ?> *24; var timer<?php echo $row['id']; ?>;  function showremaining<?php echo $row['id']; ?>() {     var now<?php echo $row['id']; ?> = new date();     var distance<?php echo $row['id']; ?> = end<?php echo $row['id']; ?> - now<?php echo $row['id']; ?>;     if (distance<?php echo $row['id']; ?> < 0 ) {        clearinterval( timer<?php echo $row['id']; ?> );        location.reload();         return;     }     var days<?php echo $row['id']; ?> = math.floor(distance<?php echo $row['id']; ?> / _day<?php echo $row['id']; ?>);     var hours<?php echo $row['id']; ?> = math.floor( (distance<?php echo $row['id']; ?> % _day<?php echo $row['id']; ?> ) / _hour<?php echo $row['id']; ?> );     var minutes<?php echo $row['id']; ?> = math.floor( (distance<?php echo $row['id']; ?> % _hour<?php echo $row['id']; ?>) / _minute<?php echo $row['id']; ?> );     var seconds<?php echo $row['id']; ?> = math.floor( (distance<?php echo $row['id']; ?> % _minute<?php echo $row['id']; ?>) / _second<?php echo $row['id']; ?> );      var countdown<?php echo $row['id']; ?> = document.getelementbyid('countdown<?php echo $row['id']; ?>');     countdown<?php echo $row['id']; ?>.innerhtml = '';     if (days<?php echo $row['id']; ?>) {         countdown<?php echo $row['id']; ?>.innerhtml += 'days: ' + days<?php echo $row['id']; ?> + '<br />';     }     countdown<?php echo $row['id']; ?>.innerhtml += 'hours: ' + hours<?php echo $row['id']; ?>+ '<br />';     countdown<?php echo $row['id']; ?>.innerhtml += 'minutes: ' + minutes<?php echo $row['id']; ?>+ '<br />';     countdown<?php echo $row['id']; ?>.innerhtml += 'seconds: ' + seconds<?php echo $row['id']; ?>+ '<br />'; }  timer<?php echo $row['id']; ?> = setinterval(showremaining<?php echo $row['id']; ?>, 1000); </script> <?php } else {     ${"winnerquery".$row['id']}= "select u_mail bids datestamp = (select max(datestamp) bids) , i_id = '".$row['id']."' limit 1";     ${"rezul".$row['id']} = mysql_query(${"winnerquery".$row['id']});     while (${"rol".$row['id']} = mysql_fetch_array(${"rezul".$row['id']})) { ${"rel".$row['id']} = ${"rol".$row['id']}['u_mail'];}     ${"relative".$row['id']} = mysql_query("update items set sold = '1',sold_to = '".${"rel".$row['id']}."' id = '".$row['id']."'");  echo "times up";   } ?> <div id="countdown<?php echo $row['id']; ?>"></div> 


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -