使用MySQL和PHP为学生分配职位

I have a database that hold student scores, I have record for individual scores and total. The problem is calculating student position.

Sample table:

sample table

You question isn’t clearly defining your problem and you didn’t even share any code either. What I understood is you have all the students in the database and their position is "nil" by default. And you want to add position to the records according to the total marks.

I'll give you high level idea of what you can do. Select all the students sorted in ascending order of their total marks. Iterate through all and update the records with the iteration number.

If you do not care about equivalent totals, you can get student position without using an update by doing something similar to the following:

SELECT student_name, total, @rownum := @rownum + 1 as position from tbl_web_users cross join (select @rownum := 0) as t order by total desc