What is the best approach to display a list of books from a database with missing entries, while still showing all numbers?

When displaying a list of books from a database with missing entries, it is important to still show all numbers in the list to maintain consistency. One approach to achieve this is to iterate through the database results and check if each entry exists. If an entry is missing, display a placeholder text instead of the book information to maintain the numbering sequence.

<?php
// Assuming $books is an array of book entries from the database

for ($i = 1; $i <= count($books); $i++) {
    if (isset($books[$i - 1])) {
        echo $i . ". " . $books[$i - 1]['title'] . "<br>";
    } else {
        echo $i . ". [Missing Entry]<br>";
    }
}
?>