Saturday, 15 May 2010

php - How do I sort data from a mysql db according to a unique and predetermined order, NOT asc or desc -



php - How do I sort data from a mysql db according to a unique and predetermined order, NOT asc or desc -

i need show 1000 test questions student, 10 per page.

the questions in mysql table, answers go in table.

i need each students questions appear in different predetermined order other students. sort order predetermined when register , placed in usermeta table.

in usermeta table there column lists order in questions should shown. order in column unique each pupil , looks example: 8|14|97|54|21|37|54|61 ...etc.

the first question shown pupil question #8, , question #14, , question #97, , on, listing 10 per page.

i don't need sort questions asc or desc. also, can alter db construction if help find solution.

also, can alter db construction if help find solution.

if changing db construction possible, instead of storing sorting order pipe separated string, store in separate table maps each question order should appear in given student. i.e.

student_id, sort_order, question_id 1 1 8 1 2 2 1 3 97

then bring together on sorting table when selecting questions particular student.

select q.* questions q bring together questions_sorting_order qso on q.id = qso.question_id order qso.sort_order qso.student_id = :student_id

php mysql sorting

No comments:

Post a Comment