RSS Forums RSS
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2075 | Replies: 9
Reply
Join Date: Mar 2007
Posts: 11
Reputation: heliumgas is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
heliumgas heliumgas is offline Offline
Newbie Poster

Help php + mysql

  #1  
Mar 21st, 2007
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:
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2006
Location: Canada
Posts: 55
Reputation: GliderPilot is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 2
GliderPilot's Avatar
GliderPilot GliderPilot is offline Offline
Junior Poster in Training

Re: php + mysql

  #2  
Mar 21st, 2007
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.
Reply With Quote  
Join Date: Oct 2006
Location: London
Posts: 42
Reputation: UrbanSky is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 4
UrbanSky UrbanSky is offline Offline
Light Poster

Re: php + mysql

  #3  
Mar 22nd, 2007
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.
Reply With Quote  
Join Date: Mar 2007
Location: Lima
Posts: 6
Reputation: tavox is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tavox's Avatar
tavox tavox is offline Offline
Newbie Poster

Re: php + mysql

  #4  
Mar 22nd, 2007
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:
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
Reply With Quote  
Join Date: Dec 2006
Posts: 7
Reputation: tintinz is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tintinz tintinz is offline Offline
Newbie Poster

Re: php + mysql

  #5  
Mar 23rd, 2007
do it with AJAX
Reply With Quote  
Join Date: Mar 2007
Posts: 11
Reputation: heliumgas is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
heliumgas heliumgas is offline Offline
Newbie Poster

Re: php + mysql

  #6  
Mar 26th, 2007
I wood like to do it with ajax but i have never look to ajax and i need hury with this....
Reply With Quote  
Join Date: Oct 2006
Location: Beijing
Posts: 30
Reputation: VanPetrol is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
VanPetrol VanPetrol is offline Offline
Light Poster

Re: php + mysql

  #7  
Mar 27th, 2007
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
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
Reply With Quote  
Join Date: Oct 2006
Location: London
Posts: 42
Reputation: UrbanSky is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 4
UrbanSky UrbanSky is offline Offline
Light Poster

Re: php + mysql

  #8  
Mar 27th, 2007
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)
Reply With Quote  
Join Date: Mar 2007
Posts: 17
Reputation: justinm is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
justinm justinm is offline Offline
Newbie Poster

Re: php + mysql

  #9  
Mar 28th, 2007
Originally Posted by tintinz View Post
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.
Reply With Quote  
Join Date: Mar 2007
Location: Lima
Posts: 6
Reputation: tavox is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
tavox's Avatar
tavox tavox is offline Offline
Newbie Poster

Re: php + mysql

  #10  
Mar 28th, 2007
Originally Posted by justinm View Post
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
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 9:11 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC