What is the best way to store and maintain order of things?

I have an pagesEAV table that stores relationships between all pages and booksthey belong.

I need to be able to store and manage the order of the pages.

Now, the obvious solution is to keep the page index for the pages.

+---------+---------+------------+
| page_id | book_id | page_index |
+---------+---------+------------+
|       1 |       1 |          1 |
|       2 |       1 |          2 |
|       3 |       1 |          3 |
|       4 |       1 |          4 |
|       5 |       1 |          5 |
|         |         |            |
|       6 |       2 |          1 |
|       7 |       2 |          2 |
|         |         |            |
|       8 |       3 |          1 |
+---------+---------+------------+

But now imagine that you have 5,000 pages and you are moving the last page forward. This means that you have to add page_index4999 lines, which I think can become difficult.

I reviewed the implementation of a linked list in MySQL as follows:

+---------+---------+-----------+-----------+
| page_id | book_id | prev_page | next_page |
+---------+---------+-----------+-----------+
|       1 |       1 | NULL      | 2         |
|       2 |       1 | 1         | 3         |
|       3 |       1 | 2         | 4         |
|       4 |       1 | 3         | 5         |
|       5 |       1 | 4         | NULL      |
|         |         |           |           |
|       6 |       2 | NULL      | 7         |
|       7 |       2 | 6         | NULL      |
|         |         |           |           |
|       8 |       3 | NULL      | NULL      |
+---------+---------+-----------+-----------+

, , , , - , . , ( "" ( ), PHP , page_index.

books page_order , , PHP, MySQL. , MySQL. .

?

+3

All Articles