Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reloading webpage 1 Time

Status
Not open for further replies.

egmweb

Programmer
Mar 19, 2004
147
EU
Hi All.

Please I need all your help in this matter... I'm starting to program and I'm writing a little code as following:

I have a test.php querying every 20 sec a table in a mysql database requesting a value (0 or 1).

For first time the value of the table will be in 0, which means "off".

Once I change the value to "1" in the table, How can I do in Javascript to reload the website just 1 time? and keep querying the database until I change it again to "0" and refresh again??

In other words, I need to refresh all the content of the website in javascript when I change a value in the database from 0 to 1 and viceversa.

Please I need help with this.

Thanks in advance.

Eduard.
 
Yes Dan, I'm using an ajax agent to do that. to count automatically 20 sec. and query the database, but the thing is the website is refreshing every 20 sec. and I just want to refresh 1 time, and when I change the value of the table again, refresh the website just 1 time.

Thanks in advance.

Eduard
 
OK - then you should have no problems... Simply store the initial state onload, and compare that to the state returned after each 20-second call. If they differ, call "location.reload(true);".

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi dan,

Let me see if I understood.

When the page onload for first time I have to store the number "0" for example.

I have in my table of the database stored "0" as well. when I change the value to 1, should reload the page.

But it every 20 sec, will refresh the website again and so on and so forth until I change the value to 0 on the database.

I'm sorry if I don't understand, please would you please be more detailed?

Regards.

Eduard

 
On page load, store the value in a global variable - let's call it "initialDBState". Also, create another a global variable - let's call it "currentDBState".

Every 20 seconds after doing your DB call to get the latest state, store the result in "currentDBState". Then compare "initialDBState" to "currentDBState". If they are different, do the reload.

Hope this helps,
Dan




Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi Dan, Thanks for be pending.

Unfortunately, the code is not working.

I'm going to explain to you at all.

I'm making a website for an personal internet radio station, on which I have a link to a little popup which contains the plugin for windows media player. At this point I start the value of database in "0", which means that the music prerecorded is playing. If I click on Live in the backend the value of the database changes to "1", which means that I will talk by microphone and everybody should hear me. The plugin of windows media player should be refreshed very 20 sec. that the reason of the counter.

At this moment, the popup windows media player refreshes every 20 sec. and the music stops and start again... which doesn't works.

I don't know how can I make it works, the thing is I need this popup be refreshed until I change the value of the database.

If you can help me I will appreciate that.

Thanks in advance.

Eduard
 
Right - thus the confusion... what you're asking for now:

I need this popup be refreshed until I change the value of the database.

(i.e. refreshing a popup until the value changes) is not what you asked for originally:

I need to refresh all the content of the website in javascript when I change a value in the database from 0 to 1 and viceversa.

(i.e. refreshing whenever the value changes state from 0 to 1, or from 1 to 0) - so you can ignore all the information I've given you as it clearly won't be what you're looking for.

Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Yes Dan, I'm sorry if I wasn't clear from the beginning.

But finally do you understand what I need to do?

Can you please help me with it?

Thanks.

Eduard
 
You can probably use a similar solution with keeping state, but only refresh when your condition has been met.

Think through the logic yourself, and work out what those conditions are - once you have it planned out, writing the JS from what I've told you already should be fairly straightforward.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top