简体   繁体   中英

dynamic change variable from database

is there possible that changing a Javascript variable or PHP variable dynamically and show it up to user without reloading the page?

I know there are a lot about this topic and everyone seems suggest using AJAX, but I think my case is different or I could say I can't find the correct answer of my problem.

The case is, when user click a button named "go", user will jump to page2 which showing a number from a variable. Every person who click "go" button will make that variable going up by 1.

if(button == pressed){
    mysql(update row1++ on a table) << update query that change value of row1, row1 is an number or integer
    jump to page2
}

in page2 will showing the variable value and dynamically change.

select(row1 from a table)
variabletemp = row1
print variabletemp << this has to be dynamically.

I read some of another question, I can do this trick using AJAX. Put the variable value on database, and then update it ever second which the second is set by interval function.

But the problem is, I want to change the value of variabletemp when the database is updating without interval function when the user is in page2, and after the variabletemp value reach some number, lets say 4, the user who already in page2 will jump into page3 (another page).

if(variabletemp == 4){
    jump to page3
}

Is that possible? It will be great if you put some example. I use Javascript for showing the variable, and processing database through PHP.

from what i understand you are trying to "push" data to the users? if so Comet / Reverse Ajax is what youre looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM