John
John

Reputation: 460

mySQL Insert only when field is different

I am using the following sql statement:

$sql = "INSERT INTO counter (uid, placeid, lastdate) VALUES
('" . $uid . "', '" . $place->place->id . "', '" . $added . "') 
ON duplicate KEY UPDATE count = count + 1`"; 

This keep tracks of how many times people check in. I do not want multiple check ins a day, so when if someone checks in twice a day we do not record it.

If $added = lastdate, I do not want to update the count.

Can this be done with a sql statement?

Upvotes: 2

Views: 115

Answers (1)

Mark Byers
Mark Byers

Reputation: 839224

This should work:

"INSERT INTO counter (uid, placeid, lastdate) VALUES
('" . $uid . "', '" . $place->place->id . "', '" . $added . "') 
ON duplicate KEY UPDATE count = count + ('" . $added . "' <> lastdate)"

Upvotes: 1

Related Questions