diff --git a/config/sql/se/TocEntries.sql b/config/sql/se/TocEntries.sql index 86c1f990..ce7d729b 100644 --- a/config/sql/se/TocEntries.sql +++ b/config/sql/se/TocEntries.sql @@ -1,7 +1,6 @@ CREATE TABLE `TocEntries` ( - `TocEntryId` int(10) unsigned NOT NULL AUTO_INCREMENT, `EbookId` int(10) unsigned NOT NULL, `TocEntry` text NOT NULL, - PRIMARY KEY (`TocEntryId`), + `SortOrder` tinyint(3) unsigned NOT NULL, KEY `index1` (`EbookId`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/lib/Ebook.php b/lib/Ebook.php index 78e10066..415107b7 100644 --- a/lib/Ebook.php +++ b/lib/Ebook.php @@ -279,7 +279,7 @@ class Ebook{ SELECT * from TocEntries where EbookId = ? - order by TocEntryId + order by SortOrder asc ', [$this->EbookId], stdClass::class); foreach($result as $row){ @@ -1827,12 +1827,13 @@ class Ebook{ private function AddTocEntries(): void{ if($this->TocEntries !== null){ - foreach($this->TocEntries as $tocEntry){ + foreach($this->TocEntries as $sortOrder => $tocEntry){ Db::Query(' - INSERT into TocEntries (EbookId, TocEntry) + INSERT into TocEntries (EbookId, TocEntry, SortOrder) values (?, + ?, ?) - ', [$this->EbookId, $tocEntry]); + ', [$this->EbookId, $tocEntry, $sortOrder]); } } }