- Messages
- 1,682
- Reaction score
- 32
- Points
- 48
Code:
SELECT * FROM `textbook` WHERE `class`=:class ORDER BY `textbook`.`ch`
+ ---- + ----- + -- + ------ + ------ +
| .id. | class | ch | sTitle | fTitle |
+ ---- + ----- + -- + ------ + ------ +
| 6... | CK2.. | 1. | ...... | ...... |
| 7... | CK2.. | 3. | ...... | ...... |
| 8... | CK2.. | 6. | ...... | ...... |
| 115. | CK2.. | 9. | ...... | ...... |
| 116. | CK2.. | 11 | ...... | ...... |
| 9... | CK2.. | 13 | ...... | ...... |
| 10.. | CK2.. | 15 | ...... | ...... |
| 11.. | CK2.. | 17 | ...... | ...... |
| 12.. | CK2.. | 20 | ...... | ...... |
| 13.. | CK2.. | 22 | ...... | ...... |
+ ---- + ----- + -- + ------ + ------ +
Let's say i bring up the chapter for 11.
Code:
SELECT * FROM `textbook` WHERE `class`=:class AND `ch`=:ch"
+ ---- + ----- + -- + ------ + ------ +
| .id. | class | ch | sTitle | fTitle |
+ ---- + ----- + -- + ------ + ------ +
| 116. | CK2.. | 11 | ...... | ...... |
+ ---- + ----- + -- + ------ + ------ +
I also want to have previous and next buttons. But the design flaw in the database is that I can't just do a `ch`+1 or a `ch`-1 because they are not all in sequencial order.
I figured that I can make another column `order`, but I do not want to add unneccessary columns to the database.
Another way I was thinking would to have all the values of `ch` in an array and try to sort it somehow.
I could be overlooking a very simple solution.
Note:
~I am using PDO.