471,089 Members | 1,251 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 software developers and data experts.

Passing values from JavaScript into MySQL/PHP


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

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.

************************************************** **************************


<script language="JavaScript">
//configure refresh interval (in seconds)
var countDownInterval=<?php echo $somePhpVariable ?>; // THIS IS WHERE
//configure width of displayed text, in px (applicable only in NS4)
var c_reloadwidth=200

<ilayer id="c_reload" width=&{c_reloadwidth}; ><layer id="c_reload2"
width=&{c_reloadwidth}; left=0 top=0></layer></ilayer>


var countDownTime=countDownInterval+1;
function countDown(){
if (countDownTime <=0){
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.writ e('Next <a
href="javascript:window.location.reload()">refresh </a> in <b
id="countDownText">'+countDownTime+' </b> seconds')
document.c_reload.document.c_reload2.document.clos e()
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')

if (document.all||document.getElementById)

Jul 23 '05 #1
2 4838
RootShell wrote:

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.


AFAIK there are no Javascript functions that allow for MySQL interaction.
That aside, storing the value in the database seems an inefficient solution.

Have you tried putting the countdown variable into a cookie? Such a
procedure could be:
onload {
get countdown from cookie
if countdown is set
resume countdown
begin new countdown

When the user clicks the reload link, you could call a function that puts
the current countdown value into the cookie.

Hope that helps.


Jason, aka The Blue Raja
Jul 23 '05 #2
JRS: In article <41**********************@news.telepac.pt>, dated Mon,
26 Jul 2004 01:45:45, seen in news:comp.lang.javascript, RootShell
<AN***************@Netcabo.ptANTISPAM> posted :
counter=setTimeout("countDown()", 1000);

That will not count seconds accurately.

See current thread "Countdown timer inaccurate - losing time!?!" in
c.l.j, and the FAQ, via below.

Is a.c.l.j generally considered valid? I think Demon does not carry it.

John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://jibbering.com/faq/> JL / RC : FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Raju V.K | last post: by
3 posts views Thread by domeceo | last post: by
2 posts views Thread by Geoff Cox | last post: by
5 posts views Thread by Lazandra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.