How to insert only one record per day?
my coding had regarding crontab in linux and php, what I want to do is my cronjob datetime is * * * * *, that mean it every minute also will checking the result, so once my result had check complete , it will insert to database, but now my results are keep inserting to database, so how to everyday insert only one record in database with the cronjob run every minute or how to stop keep inserting result to databas开发者_如何转开发e?
thank you hope you guys reply me soonest
Do the following:
- Add a date field to the record and make it unique.
- Modify your job to check if there is an record - if so, don't insert a new one.
You have to check if you have already inserted the date. Assuming your table is Table
and column that stores date is date
as timestamp
$sql = "select * from Tablewhere DATE(`date`) = CURRENT_DATE()";
$result = mysql_query($sql);
if (mysql_num_rows($result)>0){
//you already have inserted current date, handle this as you need
}
else{
//current date have not beed inserted, insert it as usual
}
This code does not check for sql errors and does not use prepared statments, but it's simple and provides you with a good idea to start.
精彩评论