Search the Community
Showing results for tags 'mysql query switch'.
-
I teach 6 different class groups, named "A" to "F", respectively. I have a small homework database from which I want to display the most recent 1 item of homework (record) for the class groups I have on any particular day of the week. So, for example, if it's Monday today, I want to display 5 items of homework, in order, for groups "A", "B", "C", "D" and "E". On the other hand, if it's Thursday today, I want to display 3 items of homework, in the order "F", "E" and "D", as that is the way my class groups are ordered on Thursday. I've created a switch statement and a select query as follows but the query isn't pulling the records out as I want them. Can anyone tell me what I'm doing wrong in the select query? How should I combine the auto-incrementing id column and the classgroups column so that the records are displayed as I want them?... (Right now, Tuesday, it's displaying D, C, B, A but it should be displaying A, B, C, D…) TIA switch (date("l")) { case 'Monday': $ord = "`id` DESC, FIELD(`classgroup`, 'A', 'B', 'C', 'D', 'E')"; $lim = 5; break; case 'Tuesday': $ord = "`id` DESC, FIELD(`classgroup`, 'A', 'B', 'C', 'D')"; $lim = 4; break; case 'Wednesday': $ord = "`id` DESC, FIELD(`classgroup`, 'F', 'C', 'E')"; $lim = 3; break; case 'Thursday': $ord = "`id` DESC, FIELD(`classgroup`, 'F', 'E', 'D')"; $lim = 3; break; case 'Friday': $ord = "`id` DESC, FIELD(`classgroup`, 'F', 'B', 'A')"; $lim = 3; break; } $q = "SELECT `id`, `classgroup`, `body`, `pointcles`, `arevoir`, DATE_FORMAT(created, '%a, %b %D') as `cr` FROM `homework` ORDER BY $ord LIMIT $lim";