UPDATE userpostratings SET rating = $rating WHERE postID = 8
如果在postpostratings中没有一行,postID = 8,我想改为INSERT。这可以用sql完成,还是我应该在php
中完成由于
托梅克
答案 0 :(得分:4)
答案 1 :(得分:2)
如果你在postID上有一个UNIQUE索引,那么你可以这样做:
INSERT INTO userpostratings (rating, postID) VALUES ($rating, 8)
ON DUPLICATE KEY UPDATE rating = $rating;
答案 2 :(得分:-1)
你去吧
http://nl2.php.net/manual/en/function.mysql-affected-rows.php
> mysql_query("UPDATE mytable SET used=1
> WHERE id < 10"); printf ("Updated
> records: %d\n",
> mysql_affected_rows());