Author Topic: do something every X seconds  (Read 1322 times)

0 Members and 1 Guest are viewing this topic.

Offline TeddyKillerTopic starter

  • Devotee
  • Posts: 1,055
  • Gender: Male
  • What is today without tomorrow or yesterday?
    • View Profile
do something every X seconds
« on: March 12, 2010, 05:11:08 PM »
I'm looking for a script that is likely to.. not refresh the page. but sometihng like..

every X seconds { do this }

How is it possible? I'll accept PHP or Javascript/Ajax
Please use [code][/code] and [php][/php] when posting code.

Please use proper PHP opening tags. <?php code here ?>

If I have posted false information, feel free to correct me.

Offline FD_F

  • Enthusiast
  • Posts: 61
  • Gender: Male
    • View Profile
Re: do something every X seconds
« Reply #1 on: March 12, 2010, 05:29:18 PM »
in this case use CRON JOB (if no user interface involve  )

Offline TeddyKillerTopic starter

  • Devotee
  • Posts: 1,055
  • Gender: Male
  • What is today without tomorrow or yesterday?
    • View Profile
Re: do something every X seconds
« Reply #2 on: March 12, 2010, 05:39:53 PM »
I've never used CRON, can you help me out? I'm needing to include php queries..
I basically need to update some things in the table every 10 seconds basically.
« Last Edit: March 12, 2010, 05:40:25 PM by TeddyKiller »
Please use [code][/code] and [php][/php] when posting code.

Please use proper PHP opening tags. <?php code here ?>

If I have posted false information, feel free to correct me.

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,255
    • View Profile
Re: do something every X seconds
« Reply #3 on: March 12, 2010, 06:15:17 PM »
Quote
I basically need to update some things in the table every 10 seconds basically.

You don't need php for that then. You just execute mysql queries within a cron job. If your having problems with Cron, your question belongs in Linux help.

Offline Tazerenix

  • Enthusiast
  • Posts: 228
  • Gender: Male
  • Call me taz :D
    • View Profile
    • Tazerenix Productions
Re: do something every X seconds
« Reply #4 on: March 12, 2010, 06:23:05 PM »
you could use jQuery AJAX to load a page with the relevant information into the table every ten seconds.
Quote
"War does not determine who is right... Only who is dead" - Unknown



NOTE: Most of the code I post is untested. So hope for the best

Offline TeddyKillerTopic starter

  • Devotee
  • Posts: 1,055
  • Gender: Male
  • What is today without tomorrow or yesterday?
    • View Profile
Re: do something every X seconds
« Reply #5 on: March 12, 2010, 06:54:52 PM »
you could use jQuery AJAX to load a page with the relevant information into the table every ten seconds.

Would that mean it'd be reloading the page?
Please use [code][/code] and [php][/php] when posting code.

Please use proper PHP opening tags. <?php code here ?>

If I have posted false information, feel free to correct me.

Offline Tazerenix

  • Enthusiast
  • Posts: 228
  • Gender: Male
  • Call me taz :D
    • View Profile
    • Tazerenix Productions
Re: do something every X seconds
« Reply #6 on: March 12, 2010, 06:56:07 PM »
no. AJAX uses XMLHttpRequests so it would only reload the Table. Not the whole page
Quote
"War does not determine who is right... Only who is dead" - Unknown



NOTE: Most of the code I post is untested. So hope for the best

Offline TeddyKillerTopic starter

  • Devotee
  • Posts: 1,055
  • Gender: Male
  • What is today without tomorrow or yesterday?
    • View Profile
Re: do something every X seconds
« Reply #7 on: March 12, 2010, 06:57:24 PM »
oh no no, I don't mean a <table></table> I mean a database table. It needs to update it every 10 seconds.
Please use [code][/code] and [php][/php] when posting code.

Please use proper PHP opening tags. <?php code here ?>

If I have posted false information, feel free to correct me.

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,255
    • View Profile
Re: do something every X seconds
« Reply #8 on: March 12, 2010, 06:59:06 PM »
Your going to need to use cron unless you want to leave a browser window open and executing this ajax.

Oh, yeah, and by the way. It is possible (and very often done) to execute database queries using Ajax.

Offline Tazerenix

  • Enthusiast
  • Posts: 228
  • Gender: Male
  • Call me taz :D
    • View Profile
    • Tazerenix Productions
Re: do something every X seconds
« Reply #9 on: March 12, 2010, 07:00:26 PM »
of course it is. jQuery ajax will allow you to load a php page into a division of your page. Inside that php page just put your queries and the layout of your table
Quote
"War does not determine who is right... Only who is dead" - Unknown



NOTE: Most of the code I post is untested. So hope for the best

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,255
    • View Profile
Re: do something every X seconds
« Reply #10 on: March 12, 2010, 07:03:16 PM »
The big questions here though.

Do you want these queries to execute every 10 seconds, even when there is no one on the site? Use Cron.
Do you want these queries to execute every 10 seconds while someone views a page? Use Ajax..

Offline TeddyKillerTopic starter

  • Devotee
  • Posts: 1,055
  • Gender: Male
  • What is today without tomorrow or yesterday?
    • View Profile
Re: do something every X seconds
« Reply #11 on: March 12, 2010, 07:04:47 PM »
It'll be the AJAX one, any idea how it's done?
Please use [code][/code] and [php][/php] when posting code.

Please use proper PHP opening tags. <?php code here ?>

If I have posted false information, feel free to correct me.

Offline Tazerenix

  • Enthusiast
  • Posts: 228
  • Gender: Male
  • Call me taz :D
    • View Profile
    • Tazerenix Productions
Re: do something every X seconds
« Reply #12 on: March 12, 2010, 07:07:40 PM »
regardless. If no1 is viewing the site they dont need to be updated every ten seconds. Just set it so on pageload it loads the php page with the queries so it will update when a user goes on the site, or every 10 seconds
Quote
"War does not determine who is right... Only who is dead" - Unknown



NOTE: Most of the code I post is untested. So hope for the best

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,255
    • View Profile
Re: do something every X seconds
« Reply #13 on: March 12, 2010, 07:08:09 PM »
The Javascript.

Code: [Select]
function updateTable() {
  $.load('update.php');
}
setInterval( "updateTable()", 10000 );

You'll also need jquery which you get by adding the following line to the <head> of your document.

Code: [Select]
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"><?script>

Then just do whatever needs doing within update.php

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,255
    • View Profile
Re: do something every X seconds
« Reply #14 on: March 12, 2010, 07:08:58 PM »
Quote
regardless. If no1 is viewing the site they dont need to be updated every ten seconds.

You don't have enough information to be able to state that as a fact.