•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 402,894 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,063 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1884 | Replies: 9
![]() |
•
•
Join Date: Mar 2007
Posts: 11
Reputation:
Rep Power: 2
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:
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
Location: Beijing
Posts: 30
Reputation:
Rep Power: 2
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
Location: London
Posts: 42
Reputation:
Rep Power: 2
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.
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.
Best regards,
Tavox@Peru
Tavox@Peru
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Genuis PHP/Mysql programmers and Awesome Designers! (Web Development Job Offers)
- PHP and MySQL Web Development (PHP)
- 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


Linear Mode