I do not know what error you have, but I would do it differently:
In for
replace $i += 1
with i++
which is the usual way of doing it and it seems clearer.
Do you make ++$num4_alumno
below and then use the variable by removing 1? If you only use this variable to get the values of $grupo
and $alumno
, make the increment at the end of for
, if you have any other function before finishing the for
, just after obtaining those values.
Then to prepare the statement, if you concatenate the variables in a String between signs {} PHP recognizes that it is a variable and is faster,
for example:
"UPDATE student_group SET assists = '{$ a}'
WHERE idAlumn = {$ al} AND idGroup = {$ gpo} "
In any case I would compose the queries, saving them in an array and execute them later.
You can do a function that only performs the execution of a group of queries, so you can put them all in a transaction or not, as the case, but above all you can print them all at a given time and see if they are correct syntactically or if they receive all the expected values.