The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
PHP-General - Dropdown box refresh rate selection
Discuss Dropdown box refresh rate selection in the PHP Development forum on Dev Shed. Dropdown box refresh rate selection PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

July 18th, 2012, 11:14 PM
|
|
Registered User
|
|
Join Date: Jun 2010
Posts: 28
  
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
|

July 19th, 2012, 08:01 AM
|
|
|
|
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.
|

July 19th, 2012, 05:09 PM
|
|
Registered User
|
|
Join Date: Jun 2010
Posts: 28
  
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
|

July 19th, 2012, 09:22 PM
|
 |
Lost in code
|
|
|
|
|
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.
|

July 19th, 2012, 09:28 PM
|
|
Registered User
|
|
Join Date: Jun 2010
Posts: 28
  
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.
|

July 19th, 2012, 10:07 PM
|
|
|
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.
|

July 19th, 2012, 10:39 PM
|
 |
Lost in code
|
|
|
|
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.
|

July 19th, 2012, 10:42 PM
|
|
Registered User
|
|
Join Date: Jun 2010
Posts: 28
  
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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|