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 "countDownInter val" 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
"countDownInter val" back into MySQL.
*************** *************** *************** *************** *************** *
********
<?PHP
$somePhpVariabl e=100;
?>
<script language="JavaS cript">
//configure refresh interval (in seconds)
var countDownInterv al=<?php echo $somePhpVariabl e ?>; // THIS IS WHERE
I PASS THE PHP VARIABLE TO JAVASCRIPT
//configure width of displayed text, in px (applicable only in NS4)
var c_reloadwidth=2 00
</script>
<ilayer id="c_reload" width=&{c_reloa dwidth}; ><layer id="c_reload2"
width=&{c_reloa dwidth}; left=0 top=0></layer></ilayer>
<script>
var countDownTime=c ountDownInterva l+1;
function countDown(){
countDownTime--;
if (countDownTime <=0){
countDownTime=c ountDownInterva l;
clearTimeout(co unter)
window.location .reload()
return
}
if (document.all) //if IE 4+
document.all.co untDownText.inn erText = countDownTime+" ";
else if (document.getEl ementById) //else if NS6+
document.getEle mentById("count DownText").inne rHTML=countDown Time+" "
else if (document.layer s){ //CHANGE TEXT BELOW TO YOUR OWN
document.c_relo ad.document.c_r eload2.document .write('Next <a
href="javascrip t:window.locati on.reload()">re fresh</a> in <b
id="countDownTe xt">'+countDown Time+' </b> seconds')
document.c_relo ad.document.c_r eload2.document .close()
}
counter=setTime out("countDown( )", 1000);
}
function startit(){
if (document.all|| document.getEle mentById) //CHANGE TEXT BELOW TO YOUR OWN
document.write( 'Next <a
href="javascrip t:window.locati on.reload()">re fresh</a> in <b
id="countDownTe xt">'+countDown Time+' </b> seconds')
countDown()
}
if (document.all|| document.getEle mentById)
startit()
else
window.onload=s tartit
</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 "countDownInter val" 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
"countDownInter val" back into MySQL.
*************** *************** *************** *************** *************** *
********
<?PHP
$somePhpVariabl e=100;
?>
<script language="JavaS cript">
//configure refresh interval (in seconds)
var countDownInterv al=<?php echo $somePhpVariabl e ?>; // THIS IS WHERE
I PASS THE PHP VARIABLE TO JAVASCRIPT
//configure width of displayed text, in px (applicable only in NS4)
var c_reloadwidth=2 00
</script>
<ilayer id="c_reload" width=&{c_reloa dwidth}; ><layer id="c_reload2"
width=&{c_reloa dwidth}; left=0 top=0></layer></ilayer>
<script>
var countDownTime=c ountDownInterva l+1;
function countDown(){
countDownTime--;
if (countDownTime <=0){
countDownTime=c ountDownInterva l;
clearTimeout(co unter)
window.location .reload()
return
}
if (document.all) //if IE 4+
document.all.co untDownText.inn erText = countDownTime+" ";
else if (document.getEl ementById) //else if NS6+
document.getEle mentById("count DownText").inne rHTML=countDown Time+" "
else if (document.layer s){ //CHANGE TEXT BELOW TO YOUR OWN
document.c_relo ad.document.c_r eload2.document .write('Next <a
href="javascrip t:window.locati on.reload()">re fresh</a> in <b
id="countDownTe xt">'+countDown Time+' </b> seconds')
document.c_relo ad.document.c_r eload2.document .close()
}
counter=setTime out("countDown( )", 1000);
}
function startit(){
if (document.all|| document.getEle mentById) //CHANGE TEXT BELOW TO YOUR OWN
document.write( 'Next <a
href="javascrip t:window.locati on.reload()">re fresh</a> in <b
id="countDownTe xt">'+countDown Time+' </b> seconds')
countDown()
}
if (document.all|| document.getEle mentById)
startit()
else
window.onload=s tartit
</script>
Comment