我試圖做一個mysql檢查$ uid是否存在從現在開始的基於$ timestamp的記錄,如果它沒有執行INSERT。mysql根據時間戳檢查今天是否存在uid記錄否則做一個插入
//EXAMPLE RECORD FROM TABLE VOTE
--- #vote_fb_uid# --- #vote_time#
665414807 1369219044
TJT
//STEP 1 - do a look up on $uid and check with timestamp $today
$timestamp = $this->time;
$date = date('Y-m-d', $timestamp);
$today = date('Y-m-d');
$sql = "
SELECT * FROM vote WHERE
vote_fb_uid = '$this->fb_uid',
WHERE vote_time = '$CHECK_IF_THERE_IS_AN_ENTRY_FROM_TODAY'";
$res = mysql_query($sql) or die(mysql_error());
//STEP 2 - If no records are found for today - then we do an INSERT
if($no_record_for_today) {
$sql = sprintf("
INSERT INTO vote(
vote_fb_uid,
vote_time)
VALUES ('%s','%s')",
mysql_real_escape_string($this->fb_uid),
mysql_real_escape_string($this->time));
$res = mysql_query($sql) or die(mysql_error());
}
顯然IM strugling與SQL部分的查找 - 我想知道是否心不是一些內置SQL函數來做到這一點或類似的?
是的。它被稱爲REPLACE – Robert
你稱之爲「今天」:過去24小時?同樣的dd.mm.yyyy? –