Below you find the code of two files. My problem is:
The functions below link the CountDown to the DIV countdown_div. But i can't show the DIV more than one time. I retrieve different rows from the database, and want to show the countdown in each row.
Thanks in advance!
- Code: Select all
$huidigedatum = date("Y-m-d H:i:s", time());
$sql = "SELECT * FROM wv_veilingen WHERE endtime > '".$huidigedatum."' ORDER BY endtime DESC";
if ($qry = mysql_query($sql)) {
while ($rij = mysql_fetch_assoc($qry)) {
include ("countdownscript.php");
echo "<div id='countdown_div'> </div>";
}
}
And the function/script:
- Code: Select all
<script>
function do_countdown() {
//var start_num = document.getElementById("value").value;
//var unit_var = document.getElementById("countdown_unit").value;
var start_num = "<?php echo $start_num; ?>" //start_num * parseInt(unit_var);
var countdown_output = document.getElementById('countdown_div');
if (start_num > 0) {
countdown_output.innerHTML = format_as_time(start_num);
var t=setTimeout("update_clock(\"countdown_div\", "+start_num+")", 1000);
}
return false;
}
do_countdown();
function update_clock(countdown_div, new_value) {
var countdown_output = document.getElementById(countdown_div);
var new_value = new_value - 1;
if (new_value > 0) {
new_formatted_value = format_as_time(new_value);
countdown_output.innerHTML = new_formatted_value;
var t=setTimeout("update_clock(\"countdown_div\", "+new_value+")", 1000);
} else {
countdown_output.innerHTML = "Veiling afgelopen";
}
}
function format_as_time(seconds) {
var days = parseInt(seconds/60/60/24);
var hours = parseInt(seconds/60/60) - (days*24);
var minutes = parseInt(seconds/60) - (hours*60) - (days*24*60);
var seconds = seconds - (minutes*60) - (hours*60*60) - (days*24*60*60);
if (days < 10) {
days = "0"+days;
}
if (hours < 10) {
hours = "0"+hours;
}
if (minutes < 10) {
minutes = "0"+minutes;
}
if (seconds < 10) {
seconds = "0"+seconds;
}
if (days < 2){
dagen = "dag";
}
else
{
dagen = "dagen";
}
var return_var = 'Nog <strong>'+days+'</strong> '+dagen+'<br><strong>'+hours+'</strong> uur <strong>'+minutes+'</strong> min <strong>'+seconds+'</strong> sec';
return return_var;
}
</script>

