944,111 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2824
  • PHP RSS
Mar 21st, 2007
0

php + mysql

Expand Post »
Hello

I´m trying to make a function that give-me data from a data base mysql at time there is no problem but i would like to now how i can make that funcion to be called from x hover x seconds, the ideia is just to se if there is a new data on the database without having to press f5!!!!:eek:

this is for a roller panell with news on it and when a new noticie is put on datebase the page can load on it without refresh.....

sorry for my english but i´m not good at it....:mrgreen:
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
heliumgas is offline Offline
11 posts
since Mar 2007
Mar 21st, 2007
0

Re: php + mysql

I can't think of any way to do it with PHP.. PHP does not do things at runtime, it is all processed by the server than converted into something your browser understands. you might have better luck withsomething like ASP or Java or Javascript.
Reputation Points: 8
Solved Threads: 2
Junior Poster in Training
GliderPilot is offline Offline
57 posts
since Sep 2006
Mar 22nd, 2007
0

Re: php + mysql

Javascript is definatly the way forwards. You can either use javascript to refresh or you can use an AJAX query to get fresh data and update you page.
Reputation Points: 10
Solved Threads: 4
Light Poster
UrbanSky is offline Offline
42 posts
since Oct 2006
Mar 22nd, 2007
0

Re: php + mysql

That's correct, you must use javascript to do that, either with ajax or japascript, i have a complete example that uses a countdown timer to control the time a user have to answer a question, you can see it at: Trivia Game

In this example i use a combination of php, javascript and a HTML Template to output the related choices of any questions that are stored in a MySql database and other stuff.

Apart from the registration process It works following this sequence:
  1. Check User: if the user that tries to play is a registered user and if this user is logged in, if not redirects to the login page.
  2. Check plays per day: Verify how many times a user plays the Trivia per day, no one can play more than 5 times per day, this value is configurable.
  3. Check questions per test: Verify the number of questions played per test, also this value is configurable and if the user reach the max number of questions finish the play and compute and store the results.
  4. Load Template: Verify if the template file can be opened, if not the script finish otherwise continue and stores the file in a temporary variable.
  5. Calculate number of questions.
  6. Pick and populate a random question.
  7. Select and populate the question's related choices.
  8. Build form's output for the choices using radio inputs.
  9. Get and set the initial time for the timer.
  10. Build some hidden fields especially the one for the count down timer.
  11. Replace the result value of the template that will be showed if a question have already answered.
  12. Replace the values of the template with all the data obtained before.
  13. Finally show the output to the user.
Something very important is that the template file -a HTML file- includes the necesary javascript code that controls the timer, without it, it dont work fine, also this file includes the design layout, the form's tag, a submit button and a simple input text box that dynamically shows how many seconds are left, when this time reach 0 or when the user press the submit button simply process the question and computes the results, then goes or to the next question or finishes the played test.

This is the code for the timer located in the template file between the form tag:
PHP Syntax (Toggle Plain Text)
  1. Time Left: <input type="text" name="seconds" size="3">
  2. <script type="text/javascript">
  3. var myTime = 20;
  4. function countDown() {
  5. document.form.seconds.value = myTime;
  6. if (myTime == 0) {
  7. idq=document.form.idquestion.value;
  8. for (i=0;i<document.form.answer.length;i++) {
  9. if (document.form.answer[i].checked==true) {
  10. ida=document.form.answer[i].value;
  11. }
  12. }
  13. location.href="trivia1.php?idquestion="+idq+"&answer="+ida;
  14. }
  15. else if (myTime > 0) {
  16. myTime--;
  17. setTimeout("countDown()",1000);
  18. }
  19. }
  20. countDown();
  21. </script>
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tavox is offline Offline
7 posts
since Mar 2007
Mar 23rd, 2007
0

Re: php + mysql

do it with AJAX
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tintinz is offline Offline
7 posts
since Dec 2006
Mar 26th, 2007
0

Re: php + mysql

I wood like to do it with ajax but i have never look to ajax and i need hury with this....
Reputation Points: 10
Solved Threads: 0
Newbie Poster
heliumgas is offline Offline
11 posts
since Mar 2007
Mar 27th, 2007
0

Re: php + mysql

Isn't there a meta tag that force your page to refresh every 'n' seconds? Cant remember the syntax right now (google it)
Then when the page load, read the database....?
But then, these mates know more than I do, and would have suggested it if it could work, seeing it's so simple
Reputation Points: 10
Solved Threads: 0
Light Poster
VanPetrol is offline Offline
30 posts
since Oct 2006
Mar 27th, 2007
0

Re: php + mysql

Yes you are quite right

you just stick something like

<meta http-equiv="refresh" content="600">
in the head section of your html document. The thing is that it is not good to take over the refresh control of a users browser because it can really get on your nerves, especially if you trying to read something.

Also you have to think about how people use the web. Most people don't stay on one page and just keep reloading it, often people browse lots of pages and just keep coming back to the homepage, to look for new news or you can put the new box on every page,that way when ever the user changes pages the script will automatically check for new news items.

Speaking from experiance I think that you are getting into a situation of over development where while you are testing the script is really tedius, so you are trying to create what of automating it but in real life you just end up taking the automation that you have spend hours out because it is just not practical or useful.

(My 2 cents worth)
Reputation Points: 10
Solved Threads: 4
Light Poster
UrbanSky is offline Offline
42 posts
since Oct 2006
Mar 28th, 2007
0

Re: php + mysql

Click to Expand / Collapse  Quote originally posted by tintinz ...
do it with AJAX
easiest way, and you don't need to refresh any part of the page either...

using javascript, you can use a div or iframe & set a timer to refresh that part of the screen at x amount of mins/hours.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
justinm is offline Offline
17 posts
since Mar 2007
Mar 28th, 2007
0

Re: php + mysql

Click to Expand / Collapse  Quote originally posted by justinm ...
easiest way, and you don't need to refresh any part of the page either...

using javascript, you can use a div or iframe & set a timer to refresh that part of the screen at x amount of mins/hours.
I think that if you are in a hurry this recommendation will help you a lot, simply include an iframe with the refresh meta tag in your main document, that way only that part of your page will be reloaded x seconds.
Of course, that iframe must include all the code to connect, retrieve the data and disconect to your database.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tavox is offline Offline
7 posts
since Mar 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Parse error: parse error, unexpected $end
Next Thread in PHP Forum Timeline: PHP templates





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC