user2967211
user2967211

Reputation: 71

PHP/MYSQL Update only first row with defined value

I want to update my database using constraints

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);}
}

I have multiple users with a $starttime of 22:00, but i only want the first users detail to be updated leaving the rest unchanged. how would i go about doing this?

Upvotes: 5

Views: 6318

Answers (1)

Cameron
Cameron

Reputation: 572

If you only want one record to be changed you can append this to the end of your statement:

LIMIT 1

For example:

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

Upvotes: 5

Related Questions