Reputation: 59
I have questions stored in my database. I want to regularly post one question on my website from the database at a 24 hr interval automatically. Is there a way I can do that ?
Upvotes: 2
Views: 2071
Reputation: 7019
Create a PHP script to select and post a particular question randomly.
In your main php script write an AJAX method(which will load the PHP script) which can be called using setInterval()
using the following syntax-
setInterval("AJAX_fun()", 24*3600*1000);
This statement will call the AJAX function in a periodic interval of 24hrs. For that you must know AJAX. I mean what should be the body of the AJAX to load the PHP script that you must have an idea of.
You can simply reload the page using javascript setInterval()
function
i.e. <script>setInterval("window.location.reload()", 24*3600*1000);</script>
and before that you have to select a question from the database randomly using a PHP logic.
Upvotes: 0
Reputation: 37365
You can do this with steps:
cron
format is provided here)Example (cron)
0 2 * * * /usr/bin/php /path/to/insert/script.php
-in this case every day at 02:00 AM
cron will try to execute command /usr/bin/php /path/to/insert/script.php
- i.e. if your script.php
will extract your question from DB and post it - that will do the stuff.
Upvotes: 1
Reputation: 371
Create a php file put the code to fetch question form your database then set cronjob to excecute the file on perticular time or also you can execute file by including it your login or any other page which lods first by including that php file file so that when first user logs in it will execute.
Upvotes: 0
Reputation: 8635
Yes, you can. I will shortly outline the two most common solutions. The difficulty rises that PHP is not an always running program, but is a language executed on request and then shutdown on completion.
Upvotes: 0
Reputation: 468
Write a script that will post one question on your website everyday and set a cron job to run that script once a day and you are done.
How to set a cron job , ask you hosting service provider , most of the hosts have this feature in cpanel
Upvotes: 0
Reputation: 360
The only way to do it correctly is to use cron jobs. You should take a look at the administration panel of your hosting service.
Upvotes: 0
Reputation: 9857
You should look into MySQL date functions.
A contrived example would be using CURDATE():
SELECT * FROM questions WHERE publish_date = CURDATE()
Storing the publish_date
will mean you can dynamically load the question when that date arrives.
Upvotes: 0
Reputation: 109
Providing you could create a PHP script to select a different question each time, all you'd need to do would be to set up a cron to run the PHP script every 24 hours. You can find more info on cron here.
Upvotes: 0
Reputation: 7776
Yes you can do it by using Cron job . Set time interval and your file script location. It will automatically hit your script on that time interval.
Here is good tutorial : http://docs.phplist.com/SetupCronJob.html
Upvotes: 0