04-04-2009, 05:32 PM
|
#7 (permalink)
|
|
The Gregarious
Join Date: Feb 2009
Location: New York
Posts: 645
Thanks: 64
|
Quote:
Originally Posted by Krik
Now here is were having good programing skills will come into play.
The first issue of counting down instead of up. While I do not wish to be coy in my answer the solution to that is the same as if you were doing it in PHP. Think of the "myfunc" function as a while or a foreach loop. And you have 93 rows of data that need to be looped through and you now wish to loop from the last row to the first. There is a slight difference but the same principle.
I could answer the question directly but as the solution to your second problem is so in depth it will role that solution in with it.
|
Ok, I kinda understand, does it have to do with the counter iterator? So instead of $i++ it should be $-- so it counts down?
I also changed the "nextrow <= rowcount" to "nextrow >= rowcount".
Here's my current code, I added an extra row to show what the DIV tags are displaying so that you don't have to do a view page source...I'm not getting any output though....
Also, I guess I should have mentioned this, the countdown will typically start at 100 seconds then down to 0 for each row. It kinda depends on what is in the DB, but for this example, we could just say 100 seconds as the starting number....
http://www.gatebattle.com/countdown.html
Code:
<?php
$rowcount = 4;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript">
var rowcount = <?php echo $rowcount; ?>;
</script>
<script type="text/javascript">
var nextrow = 1;
var endcount = true;
function multiCountDown(){
if (nextrow >= rowcount) {
if (document.getElementById('mycount'+nextrow).innerHTML != 0) {
document.getElementById('mycount'+nextrow).innerHTML = document.getElementById('mycount'+nextrow).innerHTML - 1;
endcount = false;
}
nextrow--;
multiCountDown();
}
else {
if(!endcount) {
nextrow = 1;
endcount = true;
counter = setTimeout("multiCountDown();", 1000);
}
else {
clearTimeout(counter);
}
}
}
</script>
</head>
<body onload="multiCountDown()">
<p>Rowcount is set to: $rowcount = 4; </p>
<table width="750" border="1" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center">#</div></td>
<td><div align="center">Countdown</div></td>
<td><div align="center">Username</div></td>
<td><div align="center">Location</div></td>
</tr>
<? for($i=0;$i<$rowcount;$i++) {
$mycount = "mycount" . "$i";
?>
<tr>
<td><div align="center"><? echo $i; ?></div></td>
<td><div align="center"><div id="<? echo $mycount; ?>"></div></div></td>
<td><div align="center">johnd</div></td>
<td><div align="center">NY</div></td>
</tr>
<tr bgcolor="#EEEEEE">
<td><div align="center"></div></td>
<td><div align="center">Show DIV code, ID is: ID="<? echo $mycount; ?>" </div></td>
<td><div align="center"></div></td>
<td><div align="center"></div></td>
</tr>
<? } ?>
</table>
</body>
</html>
|
|
|
|