I know how to do basic sorting according to id number or alphabetical sorting based on, say, the last name of a person. I also figured out how to sort using criteria from multiple tables, but I am curious the method someone would use to sort rows away from each other. Let me explain.
Let's say I have a database for a grade school musical act. I have 20 students. So I put them in the database for each act they are in.
Let me just give you an example table and what I would want the output to be.
So here is my table of students and the acts they are in.
id - name - act_number
1 - bobby - 1
2 - sue - 1
3 - bobby - 2
4 - kim - 3
5 - larry - 4
6 - mark - 5
7 - tommy - 6
8 - edward - 7
9 - nathan - 8
10 - scotty - 9
11 - henry - 9
12 - scotty - 10
13 - rick - 10
I basically want to sort this list to produce the nights schedule. If one kid is in back to back acts then he wouldn't have time to change, so we cant have that. If I were to sort the act numbers ascending then they would go 1-10. But that would place bobby in back to back acts, and scotty in back to back acts. I would like it to order the acts so that they wouldn't be close to each other. So I would want the act order to be something like
1
9
3
4
5
2
10
6
7
8
This way the nights schedule would give them time to change. Now say by rearranging the acts like I did above it put someone else back to back, how would I get it to sort the list so that no students were back to back?
So if the table were in this order(putting sue in act 1 and 9:
id - name - act_number
1 - bobby - 1
2 - sue - 1
3 - bobby - 2
4 - kim - 3
5 - larry - 4
6 - mark - 5
7 - tommy - 6
8 - edward - 7
9 - nathan - 8
10 - scotty - 9
11 - sue - 9
12 - scotty - 10
13 - rick - 10
Arranging the table by hand like I originally did would place sue in back to back acts.
Is there a way, maybe using multiple tables or a clever php script, to do this? I have done a lot of php/mysql but I if I can't figure this out I will need to hire somebody to do this for me.
In the end, say there were two shows that night. I would also not want somebody to be in the first and last act, giving them time to change before the show starts over again.
I realize mysql doesnt really care/know what physical order the rows are in so I am pretty sure this will need to be done with php. But I dont know, mysql has a TON of functions. I am reading through a lot of manuals but it is a lot of content.
Thanks for any help, even if it is a kick in the right direction.