Jump to content
MakeWebGames

Count down timer


-BRAIDZ-

Recommended Posts

  • Replies 66
  • Created
  • Last Reply

Top Posters In This Topic

Where is the gettimeleft() function defined? I can't find it anywhere in your code.

~G7470

It's in /includes/brain_file.php

Here's there snippet, I can post the complete code in a pastebin if needed

function gettimeleft($tl) {
                 if($tl  0)//MONTHS
                                {
                                 $release .= " $months Month" . ($months > 1 ? "s" : "");
                                }
                             if ($weeks > 0)//WEEKS
                                {
                             if ($months > 0)
                                {
                                 $release .= ",";
                                }
                                 $release .= " $weeks Week" . ($weeks > 1 ? "s" : "");
                                }
                             if ($days > 0)//DAYS
                                {
                             if ($months > 0 ||$weeks > 0)
                                {
                                 $release .= ",";
                                }
                                 $release .= " $days Day" . ($days > 1 ? "s" : "");
                                }
                             if ($hours > 0)//HOURS
                                {
                             if ($months > 0 ||$weeks > 0 || $days > 0)
                                {
                                 $release .= ",";
                                }
                                 $release .= " $hours Hour" . ($hours > 1 ? "s" : "");
                                }
                             if ($mins > 0)//MINUTES
                                {
                             if ($months > 0 ||$weeks > 0 || $days > 0 || $hours > 0)
                                {
                                 $release .= ",";
                                }
                                 $release .= " $mins Minute" . ($mins > 1 ? "s" : "");
                                }
                             if($secs > 0)//SECONDS
                             {
                                 if($release != "")
                                 {
                                   $release .= " and";
                                 }
                                 $release .= " $secs Second" . ($secs > 1 ? "s" : "");
                             }
                             }
                      return $release;
                  }
Link to comment
Share on other sites

The timers won't be changing like they did with the Javascript - you're using a PHP function to accomplish this, so the timers will not keep changing. They will stay the same on the page until the page is refreshed.

~G7470

I want to change the timers in my code to JavaScript, I have tried, and keep failing miserably.

As you would see with my previous comments.

Link to comment
Share on other sites

 

Explain, in detail, what your problem is now.

Also, your brain_file.php is laughable, sorry (not sorry) Please stop using mysql_*!

I did not code the brain_file.

And at the moment I really can't be stuffed going through the code changing the mysql.

And I don't see why it matters?

Link to comment
Share on other sites

I did not code the brain_file.

And at the moment I really can't be stuffed going through the code changing the mysql.

And I don't see why it matters?

It doesn't matter if you didn't code it; it's your project, maintain your files!

Because mysql_* is deprecated (and now officially dropped in PHP 7). If you (or your host) upgrades your PHP version, your application will not work.

 

I want to change the timers in my code to JavaScript, I have tried, and keep failing miserably.

[...]

Can you create a MCVE? You're pasting way too much irrelevant code, so I won't help with all that noise.

Plus, what's wrong with

Or were they not as plug-in-and-do-nothing as you'd like?

Edited by sniko
Link to comment
Share on other sites

It doesn't matter if you didn't code it; it's your project, maintain your files!

Because mysql_* is deprecated (and now officially dropped in PHP 7). If you (or your host) upgrades your PHP version, your application will not work.

 

Can you create a MCVE? You're pasting way too much irrelevant code, so I won't help with all that noise.

Plus, what's wrong with

Or were they not as plug-in-and-do-nothing as you'd like?

As I've said I can't get it working with fj_time.

I have tried numerous times to get it working and nothing, when I do the span if just returns blank

Link to comment
Share on other sites

This here what I'd like to change from the gettimeleft function to a JavaScript timer (which as stated previously I have tried changing it)

When I try it returns a blank span.

$q_ry = "SELECT *
                            FROM `fed_jailed`
                            WHERE `fj_playerid` = '".mysql_real_escape_string($_GET['XID'])."'";
                   $infed = mysql_query($q_ry);
                   if(mysql_num_rows($infed))
                   {
                      $if = mysql_fetch_array($infed);
                      echo "In federal jail for " . gettimeleft($if['fj_time']) . " 

                            Reason: " . $if['fj_reason'] . "

";
                   }
Link to comment
Share on other sites

As I've said I can't get it working with fj_time.

I have tried numerous times to get it working and nothing, when I do the span if just returns blank

 

What is the value of fj_time? A timestamp or date string? I'd redo your gettimeleft function, it's hideous... (here, I've done it for you)

Which countdown timer solution are you using?

[uSER=70347]NonStopCoding[/uSER] one is for the amount of seconds

[uSER=71587]~Rob0t[/uSER] one is the ending timestamp

gettimeleft function:http://makewebgames.io/forum/ge...039#post375039

Edited by sniko
  • Like 1
Link to comment
Share on other sites

And it's a time stamp

 

Ok, then most likely it's counting down from the unix timestamp (ie: 1452158818; which is over 46 years). Assuming fj_time is the time in the future, then do the following;

 

<script type="text/javascript"> var count = <?= $infed['fj_time'] - time() ?>;
var now = Math.floor(new Date().getTime() / 1000);
count = count - now;
var counter = setInterval(timer, 1000); //1000 will* run it every 1 second 

function timer() {
  count = count - 1;
  if (count == -1) {
    clearInterval(counter);
    return;
  }
  var seconds = count % 60;
  var minutes = Math.floor(count / 60);
  var hours = Math.floor(minutes / 60);
  var days = Math.floor(hours / 24);
  minutes %= 60;
  hours %= 24;
  document.getElementById("clock").innerHTML = days + " days " + hours + " hours " + minutes + " minutes and " + seconds + " seconds";
}
</script>
Link to comment
Share on other sites

 

Ok, then most likely it's counting down from the unix timestamp (ie: 1452158818; which is over 46 years). Assuming fj_time is the time in the future, then do the following;

 

<script type="text/javascript"> var count = <?= $infed['fj_time'] - time() ?>;
var now = Math.floor(new Date().getTime() / 1000);
count = count - now;
var counter = setInterval(timer, 1000); //1000 will* run it every 1 second 

function timer() {
  count = count - 1;
  if (count == -1) {
    clearInterval(counter);
    return;
  }
  var seconds = count % 60;
  var minutes = Math.floor(count / 60);
  var hours = Math.floor(minutes / 60);
  var days = Math.floor(hours / 24);
  minutes %= 60;
  hours %= 24;
  document.getElementById("clock").innerHTML = days + " days " + hours + " hours " + minutes + " minutes and " + seconds + " seconds";
}
</script>

Thanks, I am getting this though

In federal jail for -33615 days -23 hours -33 minutes and -28 seconds

Reason: Multi accounts

Link to comment
Share on other sites

1481690974

Easy fix.

  • I didn't notice on line 3 it was subtracting the current time on NSC post
  • The original calculations are wrong

I've addressed the above bullet points in this post. This should solve your problems.

 

<script type="text/javascript">
var _seconds = <?= $infed['fj_time'] - time() ?>;
var counter = setInterval(timer, 1000); //1000 will* run it every 1 second

function timer() {
  _seconds = _seconds - 1;
  if (_seconds == -1) {
    clearInterval(counter);
    return;
  }
  var days = Math.floor(_seconds / 86400);
  var hours = Math.floor((_seconds % 86400) / 3600);
  var minutes = Math.floor(((_seconds % 86400) % 3600) / 60);
  var seconds = ((_seconds % 86400) % 3600) % 60;
  document.getElementById("clock").innerHTML = days + " days " + hours + " hours " + minutes + " minutes and " + seconds + " seconds";
}
</script>
Edited by sniko
Link to comment
Share on other sites

Easy fix.

  • I didn't notice on line 3 it was subtracting the current time on NSC post
  • The original calculations are wrong

I've addressed the above bullet points in this post. This should solve your problems.

 

<script type="text/javascript">
var count = <?= $infed['fj_time'] - time() ?>;
var now = Math.floor(new Date().getTime() / 1000);
var counter = setInterval(timer, 1000); //1000 will* run it every 1 second

function timer() {
  seconds = count - 1;
  if (count == -1) {
    clearInterval(counter);
    return;
  }
  var days = Math.floor(seconds / 86400);
  var hours = Math.floor((seconds % 86400) / 3600);
  var minutes = Math.floor(((seconds % 86400) % 3600) / 60);
  var seconds = ((seconds % 86400) % 3600) % 60;
  document.getElementById("clock").innerHTML = days + " days " + hours + " hours " + minutes + " minutes and " + seconds + " seconds";
}
</script>

This is what I'm getting now..

In federal jail for -16808 days -14 hours -10 minutes and -53 seconds

Reason: Multi accounts

So god knows what's wrong with it, and by the looks of it, it's counting up, but it's not live

Link to comment
Share on other sites

This is what I'm getting now..

In federal jail for -16808 days -14 hours -10 minutes and -53 seconds

Reason: Multi accounts

So god knows what's wrong with it, and by the looks of it, it's counting up, but it's not live

 

fj_time = 1481690974

time() = 1452173271

fj_time - time() = 29517703 seconds

https://jsfiddle.net/b0fyrdt8/ (which gives the correct countdown)

How are you implementing it?!

Edited by sniko
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...