corkg Posted August 5, 2007 Share Posted August 5, 2007 I have a piece of Javascript that countsdown to 0 and then redirects. I want it to get a variable from the database which i have done and then put this into the JS so it cacountdown from the variable. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/63419-php-with-javascript/ Share on other sites More sharing options...
trq Posted August 5, 2007 Share Posted August 5, 2007 Post your current code including where you get this data from the db. Quote Link to comment https://forums.phpfreaks.com/topic/63419-php-with-javascript/#findComment-316051 Share on other sites More sharing options...
corkg Posted August 5, 2007 Author Share Posted August 5, 2007 <? session_start(); include "includes/_db_connect.php"; include "includes/_functions.php"; logincheck(); $username=$_SESSION['username']; $above = mysql_query("SELECT * FROM users WHERE username='$username'"); $info = mysql_fetch_object($above); $left = $info->lastcrime - time();?> <!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=utf-8" /> <title>Untitled Document</title> <SCRIPT LANGUAGE="JavaScript"> var start=new Date(); start=Date.parse(start)/1000; var counts= <<<<Variable here>>>>> function CountDown(){ var now=new Date(); now=Date.parse(now)/1000; var x=parseInt(counts-(now-start),10); if(document.form1){document.form1.clock.value = x +" Seconds";} if(x>0){ timerID=setTimeout("CountDown()", 1000) }else{ location.href="http://javascript.internet.com" } } // End --> </script> <SCRIPT LANGUAGE="JavaScript"> <!-- window.setTimeout('CountDown()',100); --> </script></head><body><? echo"$left" ?><FORM NAME="form1"> You are being redirected in <INPUT TYPE="text" NAME="clock" readonly style="border:0"> </FORM> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/63419-php-with-javascript/#findComment-316053 Share on other sites More sharing options...
trq Posted August 5, 2007 Share Posted August 5, 2007 Assuming Left is the variable you want. var counts= <?php echo $left ?>; Quote Link to comment https://forums.phpfreaks.com/topic/63419-php-with-javascript/#findComment-316062 Share on other sites More sharing options...
corkg Posted August 5, 2007 Author Share Posted August 5, 2007 Thanks i was trying <?php echo "$left" ?>; Quote Link to comment https://forums.phpfreaks.com/topic/63419-php-with-javascript/#findComment-316064 Share on other sites More sharing options...
BlueSkyIS Posted August 5, 2007 Share Posted August 5, 2007 should have the exact same result either way. Quote Link to comment https://forums.phpfreaks.com/topic/63419-php-with-javascript/#findComment-316109 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.