-BRAIDZ- Posted January 2, 2016 Author Share Posted January 2, 2016 Do I need to post another snippet? I relised I posted a crappy snippet that I had been screwing around with, I will post the original shortly.. Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted January 2, 2016 Author Share Posted January 2, 2016 (edited) Paste bin of the updated code. http://pastebin.com/vBBHPbxM Edited January 2, 2016 by -BRAIDZ- Quote Link to comment Share on other sites More sharing options...
G7470 Posted January 4, 2016 Share Posted January 4, 2016 Where is the gettimeleft() function defined? I can't find it anywhere in your code. ~G7470 Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted January 5, 2016 Author Share Posted January 5, 2016 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; } Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted January 5, 2016 Author Share Posted January 5, 2016 brain_file.php: http://pastebin.com/vqfNSABY Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted January 5, 2016 Author Share Posted January 5, 2016 [uSER=70485]G7470[/uSER] can you figure it out? Quote Link to comment Share on other sites More sharing options...
G7470 Posted January 5, 2016 Share Posted January 5, 2016 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 Quote Link to comment Share on other sites More sharing options...
sniko Posted January 5, 2016 Share Posted January 5, 2016 [uSER=70485]G7470[/uSER] can you figure it out? Explain, in detail, what your problem is now. Also, your brain_file.php is laughable, sorry (not sorry) Please stop using mysql_*! Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted January 6, 2016 Author Share Posted January 6, 2016 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. Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted January 6, 2016 Author Share Posted January 6, 2016 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? Quote Link to comment Share on other sites More sharing options...
sniko Posted January 6, 2016 Share Posted January 6, 2016 (edited) 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 NonStopCodings' version: http://makewebgames.io/forum/ge...654#post278654 ~Rob0ts' version: http://makewebgames.io/forum/ge...701#post278701 Your version: http://makewebgames.io/forum/ge...734#post278734 Or were they not as plug-in-and-do-nothing as you'd like? Edited January 6, 2016 by sniko Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted January 6, 2016 Author Share Posted January 6, 2016 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 NonStopCodings' version: http://makewebgames.io/forum/ge...654#post278654 ~Rob0ts' version: http://makewebgames.io/forum/ge...701#post278701 Your version: http://makewebgames.io/forum/ge...734#post278734 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 Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted January 6, 2016 Author Share Posted January 6, 2016 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'] . " "; } Quote Link to comment Share on other sites More sharing options...
sniko Posted January 6, 2016 Share Posted January 6, 2016 (edited) 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 January 6, 2016 by sniko 1 Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted January 6, 2016 Author Share Posted January 6, 2016 I'm using nonstops version Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted January 6, 2016 Author Share Posted January 6, 2016 And it's a time stamp Quote Link to comment Share on other sites More sharing options...
sniko Posted January 7, 2016 Share Posted January 7, 2016 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> Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted January 7, 2016 Author Share Posted January 7, 2016 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 Quote Link to comment Share on other sites More sharing options...
sniko Posted January 7, 2016 Share Posted January 7, 2016 Thanks, I am getting this though In federal jail for -33615 days -23 hours -33 minutes and -28 seconds Reason: Multi accounts What is the value you're expecting? Can you give me the value of fj_time for this account? Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted January 7, 2016 Author Share Posted January 7, 2016 What is the value you're expecting? Can you give me the value of fj_time for this account? 1481690974 Quote Link to comment Share on other sites More sharing options...
sniko Posted January 7, 2016 Share Posted January 7, 2016 (edited) 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 January 7, 2016 by sniko Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted January 7, 2016 Author Share Posted January 7, 2016 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 Quote Link to comment Share on other sites More sharing options...
sniko Posted January 7, 2016 Share Posted January 7, 2016 (edited) 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 January 7, 2016 by sniko Quote Link to comment Share on other sites More sharing options...
-BRAIDZ- Posted January 7, 2016 Author Share Posted January 7, 2016 http://pastebin.com/Ddbx42ZQ Quote Link to comment Share on other sites More sharing options...
sniko Posted January 7, 2016 Share Posted January 7, 2016 http://pastebin.com/Ddbx42ZQ Ah you grabbed it before my edits. See this post again, and reimplement. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.