I’m tying to update a certain number of records , in my code here $tickets = 10 which means i need to update 10 records only in the database accroding to mysql criteria , my for loop here update all the records (100 record at once !) for my criteria , here is my code
for ($counter = 1; $counter <= $tickets; $counter++) {
$bookTicket = mysql_query("UPDATE units SET
ticketSold = 'No',
userIdFK = '$chooseUser'
WHERE BusinessreservationIdFk = '$eventId'
AND classIDfk ='$chooseClass' ")
or die(mysql_error());
if ($bookTicket)
{
echo "<br/>ticket " . $counter . " done !";
}
else
{
echo "no<br/>";
}
}
How can I achieve to update one record each time the for counts ?
You can use LIMIT in your code so your code woulde be
But I think you should use this instead so you use only 1 query at one time.
PS. I think your code would be risk to SQL injection security problem. Please look about it too.