| | |
php + mysql
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2007
Posts: 11
Reputation:
Solved Threads: 0
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:
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:
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.
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:
This is the code for the timer located in the template file between the form tag:
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:
- 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.
- 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.
- 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.
- 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.
- Calculate number of questions.
- Pick and populate a random question.
- Select and populate the question's related choices.
- Build form's output for the choices using radio inputs.
- Get and set the initial time for the timer.
- Build some hidden fields especially the one for the count down timer.
- Replace the result value of the template that will be showed if a question have already answered.
- Replace the values of the template with all the data obtained before.
- Finally show the output to the user.
This is the code for the timer located in the template file between the form tag:
PHP Syntax (Toggle Plain Text)
Time Left: <input type="text" name="seconds" size="3"> <script type="text/javascript"> var myTime = 20; function countDown() { document.form.seconds.value = myTime; if (myTime == 0) { idq=document.form.idquestion.value; for (i=0;i<document.form.answer.length;i++) { if (document.form.answer[i].checked==true) { ida=document.form.answer[i].value; } } location.href="trivia1.php?idquestion="+idq+"&answer="+ida; } else if (myTime > 0) { myTime--; setTimeout("countDown()",1000); } } countDown(); </script>
Best regards,
Tavox@Peru
Tavox@Peru
•
•
Join Date: Oct 2006
Posts: 30
Reputation:
Solved Threads: 0
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
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
If you want to use CSS to design Web sites you can't do it in a half-baked way. You are in or you're not in. - Charles Wyke-Smith
•
•
Join Date: Oct 2006
Posts: 42
Reputation:
Solved Threads: 4
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)
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)
•
•
•
•
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.
Of course, that iframe must include all the code to connect, retrieve the data and disconect to your database.
Best regards,
Tavox@Peru
Tavox@Peru
![]() |
Similar Threads
- PHP and MySQL Web Development (PHP)
- Genuis PHP/Mysql programmers and Awesome Designers! (Web Development Job Offers)
- master database with php mysql (Legacy and Other Languages)
- Flash Poll System using php/mysql for free (Graphics and Multimedia)
- PHP/MySQL programmer available (Post your Resume)
- Integrating Apache with PHP and MySQL (Linux Servers and Apache)
- Using PHP, MySQL and Apache Server (PHP)
Other Threads in the PHP Forum
- Previous Thread: Parse error: parse error, unexpected $end
- Next Thread: PHP Logic for Online Test
Views: 2592 | Replies: 9
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access action ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email error file files folder form forms function functions google header href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail menu methods mlm mod_rewrite multiple mysql neutrality oop parse paypal pdf php problem query radio random record recursion regex remote script search security select server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube





