...

View Full Version : Create a countdown clock whos base value is a UNIX timestamp...



MoreBloodWine
12-20-2010, 11:04 PM
$contestend is in a UNIX format (ex. 1292907599).

What I would like to know is this.

------- This referrel contest will end in '.$contestend.' -------

How can I make the above bit read in a countdown clock type format so it might read something like this:

------- This referrel contest will end in ??Days, ??Hrs, ??Mins & ??Secs ------

It doesnt have to be something that keeps counting if the user stays on the page for say 5 mins, just show the right figure on page load / refresh.

Ty for your time !

Old Pedant
12-20-2010, 11:43 PM
Wrong forum. This is a JavaScript question. Well, okay, if you don't care about it being a *REAL* countdown you can do it in PHP. But why?

MoreBloodWine
12-20-2010, 11:46 PM
Wrong forum. This is a JavaScript question. Well, okay, if you don't care about it being a *REAL* countdown you can do it in PHP. But why?

By real countdown I assume you mean the live aspect of it like if I left the page open it would continue to count down. I just said to leave it out for ease of coding but if it's not that difficult then by all means I think it would be nice to have the live aspect of it.

As to being in the wrong forum, I suppose I should call my bad on this one. I just assumed it could be done in PHP.

In any case, if a mod would please move this to the Js board that would be really cool ;-)

Old Pedant
12-20-2010, 11:47 PM
To do this with JS, you'd simply pass both the *CURRENT* unixtime and the ending unixtime to the JS code. That is,


<script type="text/javascript">
var curTime = <?php echo $currenttime; ?>;
var endTime = <?php echo $endtime; ?>;

... and then let JS take over ...

(Some would say you don't need to pass the current time, but if you don't, then you are hoping that the user's computer clock has the same current time as your server. So I think you are always better of passing both.)

MoreBloodWine
12-20-2010, 11:51 PM
To do this with JS, you'd simply pass both the *CURRENT* unixtime and the ending unixtime to the JS code. That is,


<script type="text/javascript">
var curTime = <?php echo $currenttime; ?>;
var endTime = <?php echo $endtime; ?>;

... and then let JS take over ...

(Some would say you don't need to pass the current time, but if you don't, then you are hoping that the user's computer clock has the same current time as your server. So I think you are always better of passing both.)

Sounds good to me and good point on the clock thing... but how diccicult do you think it would be to write this up and approx how many lines of data do you think we'd be talking ?

I suppose all that doesnt matter, for me anyway since I know absolutely nothing about Js unless I'm modifying existing code and even then I still have issues. With that said, I would need someone to write all the code for me if they wouldnt mind. With that said, to sort of make things easy it wouldnt have to be done right this minute but whenever said coder has the time to spare.

Edit: As far as current server time does shouldnt that first echo be time();

<script type="text/javascript">
var curTime = <?php echo time(); ?>;
var endTime = <?php echo $contestend; ?>;

... and then let JS take over ...

Old Pedant
12-20-2010, 11:56 PM
As far as current server time does shouldnt that first echo be time();
I dunno. I don't do PHP, remember? I could look it up, but I'll assume you are right.

MoreBloodWine
12-21-2010, 12:04 AM
I dunno. I don't do PHP, remember? I could look it up, but I'll assume you are right.

Well, alot of times I open my mouth without thinking first but time() does output the server time in a UNIX format so AFAIK I am right on that much and $contestend outputs the contest end time in a unix format thx to this small bit.

$contestend = strtotime('12/20/2010 11:59:59pm');

Anyway, wether or not your able to help out with this is no big deal since you've done alot already in my other threads but sicne I havent said this yet or don't think I have... Thx for all the help you've given me these past few days ;-)

Edit: Again, if a mod happens to stop by this thread could you please move it to the Js board, Thx !

Old Pedant
12-21-2010, 12:14 AM
<html>
<head>
<script type="text/javascript">
var curTime = Math.floor( (new Date()).getTime() / 1000 ); // replaced with PHP time(), presumably
var endTime = 1293264000; // ditto

function tick( )
{
var secs = endTime - curTime;
var days = Math.floor( secs / 86400 ); // 86400 seconds in a day
secs %= 86400;
var hrs = Math.floor( secs/ 3600 );
secs %= 3600;
var mins = Math.floor( secs / 60 );
secs %= 60;
document.getElementById("ticker").innerHTML =
days + " days, " + hrs + " hours, " + mins + " minutes, " + secs + " seconds";
++curTime;
}
</script>
</head>
<body onload="setInterval(tick,1000); tick();">
<h3>Time remaining is <span id="ticker"></span></h3>

</body>
</html>

MoreBloodWine
12-21-2010, 12:39 AM
Your my friend, if I may call you that... are a god !

Looks good: http://www.eojmarket.com/referrals/ref.php

Two things to note though, one of which you may not be able to help with since as previous said PHP isnt your thind.

1. var endTime = <?php echo $contestend; ?>;

That doesnt seem to work, $contestend is defined at the top of the file but using it in the above manner doesnt seem to work. Assuming OP doesnt have any ideas on this one does anyone else happen to know how to work the php $contestend variable in to the above Js line ?

2. This one is directed at OP since it's his code... as a value reaches 0 is it possible to have it drop off so it might read something like below which covers all possible combinations where a figure reaches 0...

1 Days, 5 Hrs, 28 Mins, 40 Secs

5 Hrs, 28 Mins, 40 Secs

28 Mins, 40 Secs

40 Secs

or even like this where a 0 might fall in the middle...

1 Days, 28 Mins, 40 Secs

1 Days, 5 Hrs, 40 Secs

Also, to take this one step further if I may and you might understand this one but can we have the s drop off when times reach single digits so...

1 Days becomes 1 Day 1 Hrs becomes 1 Hr etc...



<script type="text/javascript">
var curTime = Math.floor( (new Date()).getTime() / 1000 ); // replaced with PHP time(), presumably
var endTime = 1292907600; // ditto

function tick( )
{
var secs = endTime - curTime;
var days = Math.floor( secs / 86400 ); // 86400 seconds in a day
secs %= 86400;
var hrs = Math.floor( secs/ 3600 );
secs %= 3600;
var mins = Math.floor( secs / 60 );
secs %= 60;
document.getElementById("ticker").innerHTML =
days + " Days, " + hrs + " Hrs, " + mins + " Mins, " + secs + " Secs ";
++curTime;
}
</script>

Old Pedant
12-21-2010, 12:42 AM
(1) Should work. echo the value in the <body> of the page, just to see what it is?

(2) Fussy, fussy, fussy. *sigh*.

MoreBloodWine
12-21-2010, 12:47 AM
(1) Should work. echo the value in the <body> of the page, just to see what it is?

(2) Fussy, fussy, fussy. *sigh*.

(1) Reads 1292907599
See for yourself: http://www.eojmarket.com/referrals/ref.php

This is how it's set up at the top of the page, not that I think it should matter since the echod value is a UNIX stamp.

$contestend = strtotime('12/20/2010 11:59:59pm');

(2) No big deal just thought I might ask, if nothing else I would atleast liek the s's to drop off as the values reach single digits.

Ps; Your work is appreciated and to prove it I wil lpay for it, I just can't do anything before the 5th of Jan when my UC comes in.

Old Pedant
12-21-2010, 12:57 AM
<html>
<head>
<script type="text/javascript">
var curTime = Math.floor( (new Date()).getTime() / 1000 ); // replaced with PHP time(), presumably
var endTime = 1293264000; // ditto
endTime = curTime + 75; // JUST FOR DEMO PURPOSES
var tock = null;

function tick( )
{
var msg = "";
var secs = endTime - curTime;
++curTime;

if ( secs <= 0 )
{
clearInterval(tock);
document.getElementById("remain").innerHTML = "This contest is over";
return;
}

var show = false;
var days = Math.floor( secs / 86400 ); // 86400 seconds in a day
if ( days > 0 ) show = true;
if ( show ) msg += days + ( days != 1 ? " days, " : " day, " );

secs %= 86400;
var hrs = Math.floor( secs/ 3600 );
if ( hrs > 0 ) show = true;
if ( show ) msg += hrs + ( hrs != 1 ? " hours, " : " hour, " );

secs %= 3600;
var mins = Math.floor( secs / 60 );
if ( mins > 0 ) show = true;
if ( show ) msg += mins + ( mins != 1 ? " minutes, " : " minute, " );

secs %= 60;
msg += secs + ( secs != 1 ? " seconds" : " second" );

var t = document.getElementById("ticker");
t.innerHTML = msg;
if ( ! show ) t.style.color = "red";
}
</script>
</head>
<body onload="setInterval(tick,1000); tick();">
<h3 id="remain">Time remaining is <span id="ticker"></span></h3>

</body>
</html>

Old Pedant
12-21-2010, 01:00 AM
Show the PHP code that creates that time value you dump to the top of the page.

Show the PHP code you tried for specifying the curTime and endTime to JS.

Actuallly, show your full PHP page code from the top down to where the JS tick() function starts.

MoreBloodWine
12-21-2010, 01:06 AM
Show the PHP code that creates that time value you dump to the top of the page.

Show the PHP code you tried for specifying the curTime and endTime to JS.

The below code is everything from the file including the echo you suggested to display the value of $contestend

I also noticed in the new code you posted you have a contest end message, thats not needed because I already have that defined using an if else statement which controls the top <tr>.



<?php

$contestbegin = strtotime('12/1/2010');
$contestend = strtotime('12/20/2010 11:59:59pm');

$prize = "New Copy of Uncharted 2: Among Thieves, GoTY Edition";
$prizepic = "u2goty.jpg";
$limit = 20;

$username="USER";
$password="PASS";
$database="DBASE";

mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die ("Unable to select database");

// Query Begin //
$sql = "SELECT u1.referred_by, u2.registered, COUNT(*) AS referral_count "
. " FROM ucard AS u1, ucard AS u2 "
. " WHERE IFNULL(u1.referred_by,'') != '' "
. " AND u1.referred_by = u2.psnid AND u2.registered BETWEEN $contestbegin AND $contestend "
. " GROUP BY u1.referred_by, u2.registered "
. " ORDER BY referral_count DESC LIMIT $limit";
$data = mysql_query($sql) or die(mysql_error() . '<br />Query: ' . $sql);

$request = mysql_query("SELECT COUNT(DISTINCT(`referred_by`)) FROM `ucard` WHERE `referred_by`!='' AND registered BETWEEN $contestbegin AND $contestend");
list($numreferrers) = mysql_fetch_row($request);
mysql_free_result($request);
// Query End //

function addOrdinalSuffix($number) {
if (in_array(($number % 100),array(11,12,13))){
return $number.'th';
}
else {
switch (($number % 10)) {
case 1:
return $number.'st';
break;
case 2:
return $number.'nd';
break;
case 3:
return $number.'rd';
break;
default:
return $number.'th';
break;
}
}
}

echo '
<body style="background-color: #000000; color: #FFFFFF;" onload="setInterval(tick,1000); tick();">
<center>
';

echo $contestend;

echo '
<style type="text/css">
table#places {
border: solid 3px #9E853D;
}
table#places td {
border: solid 1px #9E853D;
}
</style>

<script type="text/javascript">
var curTime = Math.floor( (new Date()).getTime() / 1000 ); // replaced with PHP time(), presumably
var endTime = 1292907600; // ditto

function tick( )
{
var secs = endTime - curTime;
var days = Math.floor( secs / 86400 ); // 86400 seconds in a day
secs %= 86400;
var hrs = Math.floor( secs/ 3600 );
secs %= 3600;
var mins = Math.floor( secs / 60 );
secs %= 60;
document.getElementById("ticker").innerHTML =
days + " Days, " + hrs + " Hrs, " + mins + " Mins, " + secs + " Secs ";
++curTime;
}
</script>
';

echo '
<table id="places">
';

if(time() > $contestend){
echo '
<tr align="center">
<td colspan="4">
------- Sorry, but this contest ended on '.date('D. F jS, Y', strftime($contestend)).' -------
</td>
</tr>
';
}else{
echo '
<tr align="center">
<td colspan="4">
------- This referral contest will end in <span id="ticker"></span> -------
</td>
</tr>
';
}

echo '
<tr align="center">
<td colspan="3">Referral Contest Leaderboard<br />&nbsp;Number of Participants: '.$numreferrers.', Showing the top '.$limit.'&nbsp;</td>
<td style="border: 1px solid; border-color: #9E853D;">1st Place Prize:<br />&nbsp;'.$prize.'&nbsp;</td>
</tr>
';

echo '
<tr align="center">
<td>
&nbsp;Place&nbsp;
</td>
<td>
&nbsp;Referrer ID&nbsp;
</td>
<td>
&nbsp;Number of Referrals&nbsp;
</td>
<td rowspan="'.($limit + 1).'">
<img width="407" height="515" src="http://www.eojmarket.com/referrals/prizes/'.$prizepic.'">
</td>
</tr>
';

$place = 0;

for ($i = 0; $i < $limit; $i++) {

$place++;

if ($i < mysql_num_rows($data)) {

$row = mysql_fetch_array($data);
$registered = $row["registered"];

echo '
<tr>
<td>
'.addOrdinalSuffix($place).'
</td>
<td>
<a href="',"http://www.myu2sig.com/usergeneratedimages/", $row["referred_by"],".png", '" target="new_page">', $row["referred_by"], '</a>
<font size="1">(';
if ($registered >= 1){
echo date('n/j/Y', strftime($registered));
}else{
echo 'Not Recorded';
}
echo ')
</font>
</td>
<td>
'.$row["referral_count"].'
</td>
</tr>
';
} else {
echo '
<tr>
<td>
'.addOrdinalSuffix($place).'
</td>
<td>
&nbsp;
</td>
<td>
&nbsp;
</td>
</tr>
';
}
}

echo '
</table>
';

echo '
</center>
</body>
';

?>

Old Pedant
12-21-2010, 01:15 AM
OH!!! You are one of those who uses echo in PHP to output huge chunks of HTML code!

I think that's a mistake, but never mind. We'll leave it alone.

so...


...
echo '
<style type="text/css">
table#places {
border: solid 3px #9E853D;
}
table#places td {
border: solid 1px #9E853D;
}
</style>

<script type="text/javascript">
var curTime = ' . time() . ';
var endTime = ' . $endtime . ';

function tick( )
... continued ...

MoreBloodWine
12-21-2010, 01:24 AM
Thx for that but two things, the first of which I may regrest asking.

1. Why are the echo's a bad idea ?

2. Now that the below code is working, what are the modifications needing to be transfered to it from your latest block of code to get the s drop on single digits and value drops on 0 added in ?

Keeping in mind I dont need the This contest is over message since I handle that with a if else statement for the first <tr>.

BTW, Thx again for all of this ;-)



<script type="text/javascript">
var curTime = '.time().';
var endTime = '.$contestend.';

function tick( )
{
var secs = endTime - curTime;
var days = Math.floor( secs / 86400 ); // 86400 seconds in a day
secs %= 86400;
var hrs = Math.floor( secs/ 3600 );
secs %= 3600;
var mins = Math.floor( secs / 60 );
secs %= 60;
document.getElementById("ticker").innerHTML =
days + " Days, " + hrs + " Hrs, " + mins + " Mins, " + secs + " Secs ";
++curTime;
}
</script>

Old Pedant
12-21-2010, 01:27 AM
Here's how I might have written that page:


<?php

$contestbegin = strtotime('12/1/2010');
$contestend = strtotime('12/20/2010 11:59:59pm');

$prize = "New Copy of Uncharted 2: Among Thieves, GoTY Edition";
$prizepic = "u2goty.jpg";
$limit = 20;

$username="USER";
$password="PASS";
$database="DBASE";

mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die ("Unable to select database");

// Query Begin //
$sql = "SELECT u1.referred_by, u2.registered, COUNT(*) AS referral_count "
. " FROM ucard AS u1, ucard AS u2 "
. " WHERE IFNULL(u1.referred_by,'') != '' "
. " AND u1.referred_by = u2.psnid AND u2.registered BETWEEN $contestbegin AND $contestend "
. " GROUP BY u1.referred_by, u2.registered "
. " ORDER BY referral_count DESC LIMIT $limit";
$data = mysql_query($sql) or die(mysql_error() . '<br />Query: ' . $sql);

$request = mysql_query("SELECT COUNT(DISTINCT(`referred_by`)) FROM `ucard` WHERE `referred_by`!='' AND registered BETWEEN $contestbegin AND $contestend");
list($numreferrers) = mysql_fetch_row($request);
mysql_free_result($request);
// Query End //

function addOrdinalSuffix($number) {
if (in_array(($number % 100),array(11,12,13))){
return $number.'th';
}
else {
switch (($number % 10)) {
case 1:
return $number.'st';
break;
case 2:
return $number.'nd';
break;
case 3:
return $number.'rd';
break;
default:
return $number.'th';
break;
}
}
}
// **** END OF PHP BLOCK CODE ... START ORDINARY HTML CODE ****
?>
<html>
<head>
<!-- style and js really should be in the head -->
<style type="text/css">
table#places {
border: solid 3px #9E853D;
}
table#places td {
border: solid 1px #9E853D;
}
</style>

<script type="text/javascript">
// for minor amounts of PHP in middle of HTML, do this:
var curTime = <?php echo time(); ?>;
var endTime = <?php echo $endtime; ?>;

function tick( )
{
... replace all this with my new version of the code ...
}
</script>

<body style="background-color: #000000; color: #FFFFFF;" onload="setInterval(tick,1000); tick();">
<center>
<table id="places">
<?php
// PHP-dependent code:
if(time() > $contestend){
echo '
<tr align="center">
<td colspan="4">
------- Sorry, but this contest ended on '.date('D. F jS, Y', strftime($contestend)).' -------
</td>
</tr>
';
}else{
echo '
<tr align="center">
<td colspan="4" id="remain">
------- This referral contest will end in <span id="ticker"></span> -------
</td>
</tr>
';
}

... AND SO ON ...

MoreBloodWine
12-21-2010, 01:32 AM
Looks good but for curiosity sake, why the id="remain" on the one tr ?

Old Pedant
12-21-2010, 01:32 AM
1. Why are the echo's a bad idea ?


I just think they are (a) unnecessary and (b) make the code just a bit harder to read. (Just because you do, indeed, need to keep putting in all those
--- ' . $xxx . ' ---
spots to mix literals and data.)

But I'm not fanatic about it.


2. Now that the below code is working, what are the modifications needing to be transfered to it from your latest block of code to get the s drop on single digits and value drops on 0 added in ?

Just replace the entire code with the new stuff.



Keeping in mind I dont need the This contest is over message since I handle that with a if else statement for the first <tr>.
Incorrect. True, you do that *IF* they HIT the page after the contest ends. But what if they hit the page when there are only a few minutes or seconds left??? And the time expires even as they watch it go to zero?

Old Pedant
12-21-2010, 01:33 AM
Looks good but for curiosity sake, why the id="remain" on the one tr ?

It's on a <td>, not a <tr>. Wouldn't make sense on a <tr>.

See my "incorrect" in just prior post.

MoreBloodWine
12-21-2010, 01:36 AM
My bad on the TR thing and good point on the end message should the user stay on the page.

I'll work all this in and post back with results ;-)
I just think they are (a) unnecessary and (b) make the code just a bit harder to read. (Just because you do, indeed, need to keep putting in all those
--- ' . $xxx . ' ---
spots to mix literals and data.)

But I'm not fanatic about it.

Just replace the entire code with the new stuff.


Incorrect. True, you do that *IF* they HIT the page after the contest ends. But what if they hit the page when there are only a few minutes or seconds left??? And the time expires even as they watch it go to zero?

MoreBloodWine
12-21-2010, 01:51 AM
http://www.eojmarket.com/referrals/ref.php

Looks like were good so I'm marking as resolved, I would keep givin thanks to these posts but I don't want anyone (admins / mds) to think the systems bein abused. In any case, do you have a PayPal adys you;d liek me to send like $10 or something to around the 5th of Jan. ?

I know it might not seem like much given all the help provided but with everything else I got goin on with bills etc. thats about all I can spare, might be able to manage $15.

Anyway, Thx again OP !

Old Pedant
12-21-2010, 02:03 AM
I can't do it. I can't take money from somebody on UC. My son is on that, too, and I know how he struggles. Keep it and invest it and make a fortune. (Hah.)

[Now how do you afford to give away free games? You hoping the advertising revenue makes up for it??]

MoreBloodWine
12-21-2010, 02:18 AM
I can't do it. I can't take money from somebody on UC. My son is on that, too, and I know how he struggles. Keep it and invest it and make a fortune. (Hah.)

[Now how do you afford to give away free games? You hoping the advertising revenue makes up for it??]

Well, for one thing I dont plan on running any contests any time soon and besides that what gifts if any I do give away should cost me little to nothing assuming I buy them with the site donations I get if any.

That and I use adsense but the F'ed up part about that is they don't send you squat til your balances reaches $100.

Also, I don't mind tossin a few bucks your way becauase for lack of a better word you have gona above and beyond the call of duty here IMO.

In any case, I hate to look a gift horse in the mouth let alont piss anyone off but...

If a value reaches 0 and it's in the "middle" it doesnt drop off. It seems the way things are coded now values that reach 0 drop off in a left to right fashion.

Current Js being used...


<script type="text/javascript">
var curTime = '.time().';
var endTime = '.$contestend.';
var tock = null;

function tick( )
{
var msg = "";
var secs = endTime - curTime;
++curTime;

if ( secs <= 0 )
{
clearInterval(tock);
document.getElementById("remain").innerHTML = "------- Sorry, but this contest ended on '.date('D. F jS, Y', strftime($contestend)).' -------";
return;
}

var show = false;
var days = Math.floor( secs / 86400 ); // 86400 seconds in a day
if ( days > 0 ) show = true;
if ( show ) msg += days + ( days != 1 ? " Days, " : " Day, " );

secs %= 86400;
var hrs = Math.floor( secs/ 3600 );
if ( hrs > 0 ) show = true;
if ( show ) msg += hrs + ( hrs != 1 ? " Hrs, " : " Hr, " );

secs %= 3600;
var mins = Math.floor( secs / 60 );
if ( mins > 0 ) show = true;
if ( show ) msg += mins + ( mins != 1 ? " Mins, " : " Min, " );

secs %= 60;
msg += secs + ( secs != 1 ? " Secs " : " Sec " );

var t = document.getElementById("ticker");
t.innerHTML = msg;
if ( ! show ) t.style.color = "red";
}
</script>


Oh, and as far as investing UC goes, bout the only luck I have with that is making sure I always save enough for my lotto numbers which is like $12 for the month since its a twice a week drawing. Hasnt won me much yet but every once i na while I win a few bucks ($1 - $10). Either way, the lotto right now is the one thing thats keeping me sane with something to hope for aside from finding a job, lol.

The really sad part though is I've been Unemployed for just over 2yrs and I havent found a job yet and god knows I'm trying. Actually, I'm a liar, the sad part is that I'm on Tier IV right now and from what I've been reading congres has no intentions of passing a Tier V for the 99er.

The below bill AFAIK, is the only hope us 99ers have right now.

http://www.opencongress.org/bill/111-s3706/show

Also, if your interested in the data, the below site has all sorts of percentages for the diff states. It's keyed to mine (Pa) right now and looking at it the last reported unemployment rate of 8.8% in November.

http://www.bls.gov/eag/eag.pa.htm

Edit: Forgot these...

Mid 0's don't drop
http://www.eojmarket.com/referrals/end1.jpg

I really like the red value you applied for this ;-)
http://www.eojmarket.com/referrals/end2.jpg

Old Pedant
12-21-2010, 04:20 AM
Yes, the not dropping zeros in the middle was on purpose. I didn't do that, at first, and I really hated the look of it when it said these three things one right after the other:
2 Hours, 1 Minute, 1 Second
2 Hours, 1 Minute
2 Hours, 59 seconds
... then later ...
2 Hours, 1 Second
2 Hours
1 Hour, 59 Minutes, 59 Seconds

It looked MUCH more confusing than leaving the zeros in there!

It's trivial to get rid of them, but I think it's a really bad idea to do so.

MoreBloodWine
12-21-2010, 05:01 AM
Good point I guess, anyway, just thought I would ask for arguments sake.
Yes, the not dropping zeros in the middle was on purpose. I didn't do that, at first, and I really hated the look of it when it said these three things one right after the other:
2 Hours, 1 Minute, 1 Second
2 Hours, 1 Minute
2 Hours, 59 seconds
... then later ...
2 Hours, 1 Second
2 Hours
1 Hour, 59 Minutes, 59 Seconds

It looked MUCH more confusing than leaving the zeros in there!

It's trivial to get rid of them, but I think it's a really bad idea to do so.

MoreBloodWine
03-14-2011, 09:16 AM
Hey OP, Need your help but only because it's your code I goofed.

I'm combining 3 site pages in to one to make for easier editing and so far so good but on the 2nd integration which is the contest page I seemed to have broke the ticker.

http://www.myu2sig.com/index2.php?contest=show

As you can see the ticker is stuck on: ------- This referral contest will end in: Loading... -------

Everything for the ticker starts at line 5 with the following:

<body style='background-color: #000000; color: #FFFFFF;' onload='setInterval(tick,1000); tick();'>



if($contest == 'show'){
// Begin Contest Page //
echo "
<div class='contestcontent'>
<body style='background-color: #000000; color: #FFFFFF;' onload='setInterval(tick,1000); tick();'>

<style type='text/css'>
table#places {
border: solid 3px #9E853D;
}
table#places td {
border: solid 1px #9E853D;
}
</style>

<script type='text/javascript'>
var curTime = '.time().';
var endTime = '.$contestend.';
var tock = null;

function tick( )
{
var msg = '';
var secs = endTime - curTime;
++curTime;

if ( secs <= 0 )
{
clearInterval(tock);
document.getElementById('remain').innerHTML = '------- Sorry, but this contest ended on '.date('D. F jS, Y g:ia', strftime($contestend)).' -------';
return;
}

var show = false;
var days = Math.floor( secs / 86400 ); // 86400 seconds in a day
if ( days > 0 ) show = true;
if ( show ) msg += days + ( days != 1 ? ' Days, ' : ' Day, ' );

secs %= 86400;
var hrs = Math.floor( secs/ 3600 );
if ( hrs > 0 ) show = true;
if ( show ) msg += hrs + ( hrs != 1 ? ' Hrs, ' : ' Hr, ' );

secs %= 3600;
var mins = Math.floor( secs / 60 );
if ( mins > 0 ) show = true;
if ( show ) msg += mins + ( mins != 1 ? ' Mins & ' : ' Min & ' );

secs %= 60;
msg += secs + ( secs != 1 ? ' Secs ' : ' Sec ' );

var t = document.getElementById('ticker');
t.innerHTML = msg;
if ( ! show ) t.style.color = 'red';
}
</script>
";

if($prizecomment >= 1){
echo $prizecomment2;
}

echo "
<table id='places'>
";

if(time() > $contestend){

echo "
<tr align='center'>
<td colspan='4'>
------- Sorry, but this contest ended on ";
echo date('D. F jS, Y g:ia', strftime($contestend));
echo " -------
</td>
</tr>
";
}else{
echo "
<tr align='center'>
<td colspan='4' id='remain'>
------- This referral contest will end in: <span id='ticker'>Loading...</span> -------
</td>
</tr>
";
}

echo "
<tr align='center'>
<td colspan='3'>Referral Contest Leaderboard<br />&nbsp;Number of Participants:
";

while($row2 = mysql_fetch_array($data2)){
echo number_format($row2[participants]);
}

echo ", Showing the top ";
echo number_format($limit);
echo "&nbsp;</td>
<td style='border: 1px solid; border-color: #9E853D;'>1st Place Prize:&nbsp;$prize1<br />2nd & 3rd Place Prizes:&nbsp;$prize2n3</td>
</tr>
";

echo "
<tr align='center'>
<td>
&nbsp;Place&nbsp;
</td>
<td>
&nbsp;Referrer ID&nbsp;
</td>
<td>
&nbsp;Number of Referrals (";

while($row3 = mysql_fetch_array($data3)){
echo number_format($row3[usrsgained]);
}

echo ")&nbsp;
</td>
<!--<td rowspan=''.($limit + 1).''>-->
<td rowspan='16'>
$prizepic
</td>
</tr>
";

$place = 0;

for ($i = 0; $i < $limit; $i++) {

$place++;

if ($i < mysql_num_rows($data)) {

$row = mysql_fetch_array($data);
$registered = $row[registered];

echo "
<tr>
<td>
";
echo addOrdinalSuffix(number_format($place));
echo "
</td>
<td>
<a href='http://www.naughtydog.com/stats/index/'$row[referred_by]' target='new_page'>$row[referred_by]</a>
<font size='1'>(";
if ($registered >= 1){
echo date('n/j/Y', strftime($registered));
}else{
echo 'NR';
}
echo ")
</font>
</td>
<td>
";
echo number_format($row[referral_count]);
echo "
</td>
</tr>
";
} else {
echo "
<tr>
<td>
";
echo addOrdinalSuffix(number_format($place));
echo "
</td>
<td>
&nbsp;
</td>
<td>
&nbsp;
</td>
</tr>
";
}
}

echo "
</table>
</body>
</div>
";
// End Contest Page //
}else if($userlist == 'show'){

}else{

}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum