PHP / MYSQL仅更新具有已定义值的第一行

时间:2014-03-13 14:28:15

标签: php sql sql-update where

我想使用约束来更新我的数据库

for ($count = 0; $count <= $size; $count++) {
if($dayOfTheWeek[$count] == "Friday" or $dayOfTheWeek[$count] == "Saturday"){

$query = "UPDATE rota SET title='Guest' WHERE date = '$dateMonthYearArr[$count]' AND starttime = '22:00'";               
$dayresult = mysql_query($query);}
}

我有多个用户的$starttime为22:00,但我只希望更新第一个用户详细信息,其余部分保持不变。我该怎么做呢?

1 个答案:

答案 0 :(得分:2)

如果您只想更改一条记录,可以将其附加到语句的末尾:

LIMIT 1

例如:

$query = "UPDATE rota SET title='Guest' WHERE date = '$dateMonthYearArr[$count]' AND starttime = '22:00' LIMIT 1";