
MuphN
Members-
Posts
36 -
Joined
-
Last visited
MuphN's Achievements

Newbie (1/5)
0
Reputation
-
ginerjm yep you are right. I did some research and now I do understand the script. But not it gets stuck at 00:00 counter doesnt go. Just shows 00.00
-
So. If I would do this. function secondPassed() { var minutes = Math.round((seconds - 30)/60); var remainingSeconds = seconds % 60; if (remainingSeconds < 10) { remainingSeconds = "0" + remainingSeconds; } //store seconds to cookie setCookie("my_cookie",seconds,5); //here 5 is expiry days document.getElementById('countdown').innerHTML = minutes + ":" + remainingSeconds; if (seconds == 0) { clearInterval(countdownTimer); document.getElementById('countdown').innerHTML = "T"; $.ajax('includes/uhp.php', { //calls uhp.php? success: function(response) { //What this function does with response? $('#countdown').html("DUNE"); //This writes Dune in html countdown span right? } } setCookie('my_cookie', '', -1); } else { seconds--; } } Could you explain this one? Its not just to get the script working, I just need to understand so I wouldnt bother you next time guys.
-
I do realise that, but I dont really imagine how to play with ajax like that. Could you help me?
-
How can I make that js would trigger the script? The script is including the database, but js cant do that.
-
True, how would you think I should do? I mean I though countdown with cookies will help, wouldnt it be better to make a timer with server side time so for example if timer started it gets the server time, adds +60 seconds to it and makes it the finishing time, how would I do that?
-
by the <span id="countdown" class="timer"></span> - in other words it shows the outcome in this span.
-
Hello, so I have trubble with one thing, I created a countdown with cookies and javascript, and I want to do something when it counts to 0. So I tryed adding a bit php to js. Hares what I got. My main.php page (lets say its main.php). <?php include_once 'includes/uhp.php'; ?> <script type="text/javascript"> function setCookie(cname,cvalue,exdays) { var d = new Date(); d.setTime(d.getTime()+(exdays*24*60*60*1000)); var expires = "expires="+d.toGMTString(); document.cookie = cname + "=" + cvalue + "; " + expires; } function getCookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i=0; i<ca.length; i++) { var c = ca[i].trim(); if (c.indexOf(name)==0) return c.substring(name.length,c.length); } return ""; } //check existing cookie cook=getCookie("my_cookie"); if(cook==""){ //cookie not found, so set seconds=60 var seconds = 60; }else{ seconds = cook; console.log(cook); } function secondPassed() { var minutes = Math.round((seconds - 30)/60); var remainingSeconds = seconds % 60; if (remainingSeconds < 10) { remainingSeconds = "0" + remainingSeconds; } //store seconds to cookie setCookie("my_cookie",seconds,5); //here 5 is expiry days document.getElementById('countdown').innerHTML = minutes + ":" + remainingSeconds; if (seconds == 0) { clearInterval(countdownTimer); document.getElementById('countdown').innerHTML = "<?php uhpn($mysqli); ?>"; setCookie('my_cookie', '', -1); } else { seconds--; } } var countdownTimer = setInterval(secondPassed, 1000); </script> <span id="countdown" class="timer"> </span> And thats my uhp.php that I included at the top. <?php include_once 'db_connect.php'; include_once 'functions.php'; sec_session_start(); function uhpn($mysqli) { if ($stmt = $mysqli->prepare("UPDATE members SET count = count+1 WHERE id = ? LIMIT 1")) { $user_id = $_SESSION['user_id']; $stmt->bind_param('i', $user_id); // check if the query did execute and that it affected a row if ($stmt->execute() && $mysqli->affected_rows > 0) { exit; } } return false; } So I tryed setting that it would only say like TEST when the counter hits 0, it works. Everything is fine, but whenever I add the php part to the js timer end. It runs the script but it runs allways when u refresh it, but it doesnt trigger when its 00:00, and when refresh it kills the script. So I think its my php foult for some reason, it only runs the php, it doesnt cares about js part. Any help, thank you in advanced!
-
Thank you for you response. But how can I make it that it would call like two or even all rows from database and make it different I mean. function getbase($mysqli) { if ($stmt = $mysqli->prepare("SELECT level, xp, somthing, else, blah FROM members WHERE id = ? LIMIT 1")) { $user_id = $_SESSION['user_id']; $stmt->bind_param('i', $user_id); $stmt->execute(); $stmt->store_result(); if ($stmt->num_rows == 5) { $stmt->bind_result( $s, $x, $b, $f, $g); $stmt->fetch(); return $s, $x, $b, $f, $g; } } return false; } Should it be like that, Sorry Im kinda sleepy. Got it, makes sense. lu2,3,4.... actually does, it uploads some numbers to database, I guess I should use one querry somehow aswell? function lvl2($mysqli) { if ($stmt = $mysqli->prepare("UPDATE members SET level = 2, xp = xp-200 WHERE id = ? LIMIT 1")) { $user_id = $_SESSION['user_id']; $stmt->bind_param('i', $user_id); if ($stmt->execute() && $mysqli->affected_rows > 0) { header('Location: index.php'); exit; } } return false; } -------------------- function lvl3($mysqli) { if ($stmt = $mysqli->prepare("UPDATE members SET level = 3, xp = xp-500 WHERE id = ? LIMIT 1")) { $user_id = $_SESSION['user_id']; $stmt->bind_param('i', $user_id); if ($stmt->execute() && $mysqli->affected_rows > 0) { header('Location: index.php'); exit; } } return false; } =-------------- and so on. I added some lines to understand it more easy. function uXL($mysqli) { $lu2 = lvl2($mysqli); $lu3 = lvl3($mysqli); $lu4 = lvl4($mysqli); $lu5 = lvl5($mysqli); $lu6 = lvl6($mysqli); $lu7 = lvl7($mysqli); $lu8 = lvl8($mysqli); $lu9 = lvl9($mysqli); $lu10 = lvl10($mysqli); $xp = getXp($mysqli); $lvl = getLvl($mysqli); $nolvl = "You don't have enough experiance points!"; $maxlvl = "You are allready maximum level!"; //If level is 1 if ($lvl == 1) { //and xp is more or equal then 200 if($xp >= 200 ){ //does this function. $lu2; }else { //If u dont have 200 xp points it says that u dont have it. echo $nolvl; } }else if ($lvl == 2) { if($xp >= 500 ){ $lu3; }else { echo $nolvl; } }else if($lvl == 3) { if($xp >= 1000 ){ $lu4; }else { echo $nolvl; } }else if($lvl == 4) { if($xp >= 1700 ){ $lu5; }else { echo $nolvl; } }else if($lvl == 5) { if($xp >= 2500 ){ $lu6; }else { echo $nolvl; } }else if($lvl == 6) { if($xp >= 3200 ){ $lu7; }else { echo $nolvl; } }else if($lvl == 7) { if($xp >= 4000 ){ $lu8; }else { echo $nolvl; } }else if($lvl == { if($xp >= 5000 ){ $lu9; }else { echo $nolvl; } }else if($lvl == 9) { if($xp >= 6200 ){ $lu10; }else { echo $nolvl; } }else{ //level 10 or more or 0 shows that ur maximum level allready. echo $maxlvl; } } if(isset($_POST['lvlup'])) //If button is clicked, it does the function. { if(uXL($mysqli)) { //If the querry is sucsessifull it shows that u gained a level. echo "You have gained a level!"; } else { // if Not, then not. echo "some prob!"; } }
-
I dont get it before, it gets after it, it selects the ID by taking it from seesion $user_id = $_SESSION['user_id']; - this sets the user_id to Session Id, so it takes the ID from ur current session. The session starts when its set, its set on the page where u need to do stuff. $stmt->bind_param('i', $user_id); - This sets the user_id for the ? one at the prepares. It prepers frists then sets the user id from session and then executes the query. If Im correct, ughh bad at explaining.
-
function getLvl($mysqli) { if ($stmt = $mysqli->prepare("SELECT level FROM members WHERE id = ? LIMIT 1")) { $user_id = $_SESSION['user_id']; $stmt->bind_param('i', $user_id); $stmt->execute(); $stmt->store_result(); if ($stmt->num_rows == 1) { $stmt->bind_result( $lvl); $stmt->fetch(); return $lvl; } } return false; } No error, just always goes for $ul2; nothing else, doesnt matter if you are lvl 3 or lvl 5
-
Hello I have a problem. I think I cant do that, how can I go arround this, because in javascript I guess u can go else if how meny times u want to, but in php it shows an error, and cant find the mistake is it else if's or something else thats causing the trubble? function uXL($mysqli) { $lu2 = lvl2($mysqli); $lu3 = lvl3($mysqli); $lu4 = lvl4($mysqli); $lu5 = lvl5($mysqli); $lu6 = lvl6($mysqli); $lu7 = lvl7($mysqli); $lu8 = lvl8($mysqli); $lu9 = lvl9($mysqli); $lu10 = lvl10($mysqli); $xp = getXp($mysqli); $lvl = getLvl($mysqli); $nolvl = "You don't have enough experiance points!"; $maxlvl = "You are allready maximum level!"; if ($lvl == 1) { if($xp >= 200 ){ $lu2; }else { echo $nolvl; } }else if ($lvl == 2) { if($xp >= 500 ){ $lu3; }else { echo $nolvl; } }else if($lvl == 3) { if($xp >= 1000 ){ $lu4; }else { echo $nolvl; } }else if($lvl == 4) { if($xp >= 1700 ){ $lu5; }else { echo $nolvl; } }else if($lvl == 5) { if($xp >= 2500 ){ $lu6; }else { echo $nolvl; } }else if($lvl == 6) { if($xp >= 3200 ){ $lu7; }else { echo $nolvl; } }else if($lvl == 7) { if($xp >= 4000 ){ $lu8; }else { echo $nolvl; } }else if($lvl == { if($xp >= 5000 ){ $lu9; }else { echo $nolvl; } }else if($lvl == 9) { if($xp >= 6200 ){ $lu10; }else { echo $nolvl; } }else{ echo $maxlvl; } } Everything works good I tested it take the $lvl and takes the $xp but it always goes for if lvl 1 and lu2 nothing more, I did try to set in database the level 3 for testing further, but it jumped into first one again, doesnt matter witch one I set it always leads to lu2; for some reason.. Help me see the syntax mistake.
-
Hello. I need help with my js, basicly its js count down that counts to zero, I think it should be correct, umm I dont really understand the part where it says if (M > 30) { - I understand that if minutes is higher then 30 mins, y = sets a, but I need to make it that if minutes reaches 00:00 add php script <?php $uploadToDB ?> and restarts the countdown. How can I do that? Hares the script of js countdown. <HTML> <HEAD> <TITLE>Count Down Timer</TITLE> <script> //add leading zeros setInterval(function() { function addZero(i) { if (i < 10) { i = "0" + i; } return i; } var x = document.getElementById("timer"); var d = new Date(); var s = (d.getSeconds()); var m = (d.getMinutes()); var a = addZero(60 - 60); var b = addZero(60 - m); var c = (60 - s); if (m > 30) { y = a; } if (m == 0) { return true; } var t = y + (":" + addZero(c)); x.innerHTML = t; }, 250); </script> </HEAD> <BODY> <div align="center" id="timer" style='color:black;font-size:24px;' ></div> </BODY> </HTML>
-
Hello. I need information. I know how to create timer with javascript, and i managed to create a timmer with cookies as well, but not perfectly working yet, so that if user would restart the page it would still continue after it, but I need to make that it would still continue counting down if the page closed or PC even shuted down, how can I make that? What do I need to use, need your help on this one.. Thanks guys, waiting for a response.
-
Hello. So I have a problem. I have a counter that counts down to 0. And you can set the numbers to count to urself, but I need to make it that it wouldn't refresh when you refresh the whole page. I guess I should use SESSION or something, but I cant make it work for some reason. /* Function to display a Countdown timer with starting time from a form */ // sets variables for minutes and seconds var ctmnts = 0; var ctsecs = 0; var startchr = 0; // used to control when to read data from form function countdownTimer() { // http://coursesweb.net/javascript/ // if $startchr is 0, and form fields exists, gets data for minutes and seconds, and sets $startchr to 1 if(startchr == 0 && document.getElementById('mns') && document.getElementById('scs')) { // makes sure the script uses integer numbers ctmnts = parseInt(document.getElementById('mns').value) + 0; ctsecs = parseInt(document.getElementById('scs').value) * 1; // if data not a number, sets the value to 0 if(isNaN(ctmnts)) ctmnts = 0; if(isNaN(ctsecs)) ctsecs = 0; // rewrite data in form fields to be sure that the fields for minutes and seconds contain integer number document.getElementById('mns').value = ctmnts; document.getElementById('scs').value = ctsecs; startchr = 1; document.getElementById('btnct').setAttribute('disabled', 'disabled'); // disable the button } // if minutes and seconds are 0, sets $startchr to 0, and return false if(ctmnts==0 && ctsecs==0) { startchr = 0; document.getElementById('btnct').removeAttribute('disabled'); // remove "disabled" to enable the button /* HERE YOU CAN ADD TO EXECUTE A JavaScript FUNCTION WHEN COUNTDOWN TIMER REACH TO 0 */ return false; } else { // decrease seconds, and decrease minutes if seconds reach to 0 ctsecs--; if(ctsecs < 0) { if(ctmnts > 0) { ctsecs = 59; ctmnts--; } else { ctsecs = 0; ctmnts = 0; } } } // display the time in page, and auto-calls this function after 1 seccond document.getElementById('showmns').innerHTML = ctmnts; document.getElementById('showscs').innerHTML = ctsecs; setTimeout('countdownTimer()', 1000); } //--> <form> Minutes: <input type="text" id="mns" name="mns" value="0" size="3" maxlength="3" /> Seconds: <input type="text" id="scs" name="scs" value="0" size="2" maxlength="2" /><br/> <input type="button" id="btnct" value="START" onclick="countdownTimer()"/> </form> Countdown Timer: <span id="showmns">00</span>:<span id="showscs">00</span> Hare java and html.