Reputation: 71
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
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