user723128
user723128

Reputation: 61

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 database?

thank you hope you guys reply me soonest

Upvotes: 0

Views: 2910

Answers (2)

J0HN
J0HN

Reputation: 26941

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.

Upvotes: 1

Wesley van Opdorp
Wesley van Opdorp

Reputation: 14941

Do the following:

  1. Add a date field to the record and make it unique.
  2. Modify your job to check if there is an record - if so, don't insert a new one.

Upvotes: 3

Related Questions