我正在努力做到这一点:
$sql = mysql_query("SELECT COUNT(fk_player_id) count FROM wr_year WHERE fk_player_id=$currplayer AND year=2013");
$row = mysql_fetch_assoc($sql);
if($row['count'] == 0){
mysql_query("INSERT INTO wr_year (fk_player_id, year, points) VALUES ($currplayer, 2013, $points)");
} else {
mysql_query("UPDATE wr_year SET points=points+$points WHERE fk_player_id=$currplayer AND year=2013");
}
进入这个:
mysql_query("INSERT INTO wr_year (fk_player_id, year, points) VALUES ($currplayer, 2013, $points)
ON DUPLICATE KEY UPDATE points=points+$points");
但这行得通吗?我如何确保它仅在 fk_player_id 和 year 上检查 ON DUPLICATE,并且可以完成吗?
提前致谢 ;-)