Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 637
user2967211 Avatar asked Mar 13 '14 14:03

user2967211


1 Answers

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";
like image 187
Cameron Avatar answered Sep 26 '22 02:09

Cameron