Calculate average in PHP -


i have little problem.

i have virtual laboratory, student complete survey 5 questions, each costs 2 point. bad choice -2point, choice +2point.

so, @ final, when student press "show me results", want script update 'media' field table "users" , update 'nota' field table "laborator". student receive more results if has result 4, average must 4, without considering other results. attached php script, doesn't work,it didn't calculate average want.

http://pastebin.com/s55c7nyq

ps: media meaning average, nota meaning result or note, suma meaning sum, nr_note meaning number of notes.

or example :

i have:
6
5
6

if execute select if('nota'<=4,4,avg('nota')) medie laborator 'student'='teodorescu@yahoo.com'
shows 4 that's wrong , have no 4 in notes. wrong here ?

if have 1 4, average returns 4, here.

'nota' int(2)

it looks might have problem getting correct average because of results tests lumped (per user)? in other words, if student takes test many times, table not store each test separately, keeps adding results same users' overall score.

so maybe solution add field table has unique number particular test-taking, , have generate number @ beginning of test each time student begins. if test on multiple pages, you'd need pass variable page page or set cookie.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -