PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 18th, 2012, 11:14 PM
lhardee lhardee is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2010
Posts: 28 lhardee User rank is Corporal (100 - 500 Reputation Level)lhardee User rank is Corporal (100 - 500 Reputation Level)lhardee User rank is Corporal (100 - 500 Reputation Level)lhardee User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 11 h 50 m 18 sec
Reputation Power: 0
PHP-General - Dropdown box refresh rate selection

Hello,

I hope I'm asking this question in the correct forum and someone can help me.

I've got a php page displaying MySQL table of info that refreshes every 120 seconds so users can see updated info.

I would like to give users a dropdown feature to choose a refresh rate: (30 seconds, 1 minute, 5 minutes). I know this involves setting cookies to retain memory of selection, but not sure how to make this happen.

Any help would be appreciated.

Thanks,
lhardee

Reply With Quote
  #2  
Old July 19th, 2012, 08:01 AM
NotionCommotion NotionCommotion is offline
Contributing User
Click here for more information.
 
Join Date: Sep 2006
Posts: 1,464 NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level)NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level)NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level)NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level)NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level)NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level)NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level)NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level)NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level)NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level)NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level)NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 6 h 21 m 36 sec
Reputation Power: 526
Will you store the desired refresh rate individually for each user in your database? If so, don't use a cookie.

You are using JavaScript and Ajax for the autorefresh, correct? That JavaScript is setup for 120 second refresh. Is the JavaScript in a separate file, or inline with the index.php script? If inline, simply get the desired refresh rate (either by querying your database for the given user or by reading your cookie), and modify your JavaScript when you right it to the client. If it is a separate file, you can either move it to the main index.php script and do above, or create some global JavaScript variable in your main index.php script and modify the JavaScript file to use the global variable as the refresh rate.

Reply With Quote
  #3  
Old July 19th, 2012, 05:09 PM
lhardee lhardee is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2010
Posts: 28 lhardee User rank is Corporal (100 - 500 Reputation Level)lhardee User rank is Corporal (100 - 500 Reputation Level)lhardee User rank is Corporal (100 - 500 Reputation Level)lhardee User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 11 h 50 m 18 sec
Reputation Power: 0
PHP-General - Dropdown box refresh rate selection

Right now I am using meta refresh: <meta http-equiv="refresh" content="5;URL='http://example.com/'">

I wasn't planning on querying the database; just implementing a dropdown box with choices, setting a cookie, and implementing javascript to use the global variable.
However, I don't know how to make this happen. Are their any code examples that might shed light on how to accomplish this?

Thanks,

lhardee

Reply With Quote
  #4  
Old July 19th, 2012, 09:22 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,931 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 7 h 49 m 26 sec
Reputation Power: 7053
If you bind an onchange handler to your select box you can use that to automatically submit the form or redirect the user when the user changes the selection.

Then your PHP script can read the value from the form, update the cookie, and print out the appropriate meta refresh tag.

When your script loads for the first time it won't have any values coming from the form; in that case, you use the value from the cookie (assuming it exists).

Which of those steps are you unsure how to do?

This isn't the cleanest way to do it, but it is the least complicated.
__________________
PHP FAQ
How to program a basic, secure login system using PHP

Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Reply With Quote
  #5  
Old July 19th, 2012, 09:28 PM
lhardee lhardee is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2010
Posts: 28 lhardee User rank is Corporal (100 - 500 Reputation Level)lhardee User rank is Corporal (100 - 500 Reputation Level)lhardee User rank is Corporal (100 - 500 Reputation Level)lhardee User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 11 h 50 m 18 sec
Reputation Power: 0
Thanks for the response.

You said:
Which of those steps are you unsure how to do?

Pretty much all of it. I'm a total nube trying to understand as I go. I wasn't sure if it was relatively easy or rather complicated.

Reply With Quote
  #6  
Old July 19th, 2012, 10:07 PM
NotionCommotion NotionCommotion is offline
Contributing User
Click here for more information.
 
Join Date: Sep 2006
Posts: 1,464 NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level)NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level)NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level)NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level)NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level)NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level)NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level)NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level)NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level)NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level)NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level)NotionCommotion User rank is Colonel (50000 - 60000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 6 h 21 m 36 sec
Reputation Power: 526
Okay, so you have
Code:
<meta http-equiv="refresh" content="120" > 
on your page.

You want to change the 120 to something else. Set up a form. If you don't know how to do so, google php form. Then use the input of the form to echo the correct value instead of 120. If not set, default to 120.

Reply With Quote
  #7  
Old July 19th, 2012, 10:39 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,931 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 7 h 49 m 26 sec
Reputation Power: 7053
Start by not using JavaScript at all then, just have a submit button for your form.

Next, follow NotionCommotion's advice and look up a basic tutorial on forms and PHP. One that explains how to use $_GET and $_POST to access submitted values. Then build your page so that you can output those values to it dynamically.

Then read the manual page for setcookie and make as much sense of it as you can. Try to store the $_GET/$_POST value into a cookie and load the meta tag's value from the cookie instead of the $_GET/$_POST value.

After you get all of that working you can add in the JavaScript bits.

If you get stuck, post the code you've developed so far, even if it isn't working.

It's not very complicated overall.

Reply With Quote
  #8  
Old July 19th, 2012, 10:42 PM
lhardee lhardee is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2010
Posts: 28 lhardee User rank is Corporal (100 - 500 Reputation Level)lhardee User rank is Corporal (100 - 500 Reputation Level)lhardee User rank is Corporal (100 - 500 Reputation Level)lhardee User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 11 h 50 m 18 sec
Reputation Power: 0
Awesome!

Thanks for the suggestion. I will give it a shot.


lhardee

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > PHP-General - Dropdown box refresh rate selection

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap