In this example, we are going to build the Blog Dashboard, a page that lists most recently saved articles first, showing five articles at a time. The user is able to browse through all articles using the navigation links at the bottom of the list. For now we will not implement any functionality in the dashboard other than viewing each article. Moving forward in this chapter, we will use this page as our codebase to build on top of as we learn more advanced MongoDB topics:
1. Create a new file named
dashboard.php
in your text editor, and add the following PHP, HTML/CSS code there:<?php try { $mongodb = new Mongo(); $articleCollection = $mongodb->myblogsite->articles; } catch (MongoConnectionException $e) { die('Failed to connect to MongoDB '.$e->getMessage()); } $currentPage = (isset($_GET['page'])) ? (int) $_GET['page'] : 1; $articlesPerPage = 5; $skip = ($currentPage - 1) * $articlesPerPage; $cursor = $articleCollection->find...