R
RootShell
Hello
First of all i know that PHP is a server side, and JavaScript is a Client
side programming language, but i need to know if there is any way i can add
the variable "countDownInterval" from this particular FULL code into a MySQL
field.
Here's the drill:
I have a timer on a PHP webpage, and i want to prevent the user from doing a
refresh to reset the timer to it's full time (in this case 100), and i
though of since i can pass the variable from PHP into JavaScript i could
save the timer into a MySQL field and each time the user refreshs the page
it's fethed from MySQL and passed by PHP back into JavaScript.
So it user has only 5 seconds left, and uses a refresh, the script fetchs
the value 5 from MySQL table and continues to count down from there.
Is this possible? Let's me refrase that i only need a way to pass a variable
from this JavaScript into MySQL, and that the page cannot be refreshed by
it's own, since it has some pictures and it takes some time to load. the
timer is on a <ilayer>
HERE'S my example code, that shows how to pass values from PHP into
JavaScript, please complete it in a way i can pass variable
"countDownInterval" back into MySQL.
****************************************************************************
********
<?PHP
$somePhpVariable=100;
?>
<script language="JavaScript">
//configure refresh interval (in seconds)
var countDownInterval=<?php echo $somePhpVariable ?>; // THIS IS WHERE
I PASS THE PHP VARIABLE TO JAVASCRIPT
//configure width of displayed text, in px (applicable only in NS4)
var c_reloadwidth=200
</script>
<ilayer id="c_reload" width=&{c_reloadwidth}; ><layer id="c_reload2"
width=&{c_reloadwidth}; left=0 top=0></layer></ilayer>
<script>
var countDownTime=countDownInterval+1;
function countDown(){
countDownTime--;
if (countDownTime <=0){
countDownTime=countDownInterval;
clearTimeout(counter)
window.location.reload()
return
}
if (document.all) //if IE 4+
document.all.countDownText.innerText = countDownTime+" ";
else if (document.getElementById) //else if NS6+
document.getElementById("countDownText").innerHTML=countDownTime+" "
else if (document.layers){ //CHANGE TEXT BELOW TO YOUR OWN
document.c_reload.document.c_reload2.document.write('Next <a
href="javascript:window.location.reload()">refresh</a> in <b
id="countDownText">'+countDownTime+' </b> seconds')
document.c_reload.document.c_reload2.document.close()
}
counter=setTimeout("countDown()", 1000);
}
function startit(){
if (document.all||document.getElementById) //CHANGE TEXT BELOW TO YOUR OWN
document.write('Next <a
href="javascript:window.location.reload()">refresh</a> in <b
id="countDownText">'+countDownTime+' </b> seconds')
countDown()
}
if (document.all||document.getElementById)
startit()
else
window.onload=startit
</script>
First of all i know that PHP is a server side, and JavaScript is a Client
side programming language, but i need to know if there is any way i can add
the variable "countDownInterval" from this particular FULL code into a MySQL
field.
Here's the drill:
I have a timer on a PHP webpage, and i want to prevent the user from doing a
refresh to reset the timer to it's full time (in this case 100), and i
though of since i can pass the variable from PHP into JavaScript i could
save the timer into a MySQL field and each time the user refreshs the page
it's fethed from MySQL and passed by PHP back into JavaScript.
So it user has only 5 seconds left, and uses a refresh, the script fetchs
the value 5 from MySQL table and continues to count down from there.
Is this possible? Let's me refrase that i only need a way to pass a variable
from this JavaScript into MySQL, and that the page cannot be refreshed by
it's own, since it has some pictures and it takes some time to load. the
timer is on a <ilayer>
HERE'S my example code, that shows how to pass values from PHP into
JavaScript, please complete it in a way i can pass variable
"countDownInterval" back into MySQL.
****************************************************************************
********
<?PHP
$somePhpVariable=100;
?>
<script language="JavaScript">
//configure refresh interval (in seconds)
var countDownInterval=<?php echo $somePhpVariable ?>; // THIS IS WHERE
I PASS THE PHP VARIABLE TO JAVASCRIPT
//configure width of displayed text, in px (applicable only in NS4)
var c_reloadwidth=200
</script>
<ilayer id="c_reload" width=&{c_reloadwidth}; ><layer id="c_reload2"
width=&{c_reloadwidth}; left=0 top=0></layer></ilayer>
<script>
var countDownTime=countDownInterval+1;
function countDown(){
countDownTime--;
if (countDownTime <=0){
countDownTime=countDownInterval;
clearTimeout(counter)
window.location.reload()
return
}
if (document.all) //if IE 4+
document.all.countDownText.innerText = countDownTime+" ";
else if (document.getElementById) //else if NS6+
document.getElementById("countDownText").innerHTML=countDownTime+" "
else if (document.layers){ //CHANGE TEXT BELOW TO YOUR OWN
document.c_reload.document.c_reload2.document.write('Next <a
href="javascript:window.location.reload()">refresh</a> in <b
id="countDownText">'+countDownTime+' </b> seconds')
document.c_reload.document.c_reload2.document.close()
}
counter=setTimeout("countDown()", 1000);
}
function startit(){
if (document.all||document.getElementById) //CHANGE TEXT BELOW TO YOUR OWN
document.write('Next <a
href="javascript:window.location.reload()">refresh</a> in <b
id="countDownText">'+countDownTime+' </b> seconds')
countDown()
}
if (document.all||document.getElementById)
startit()
else
window.onload=startit
</script>