O'Reilly logo

PHP and MongoDB Web Development by Rubayeet Islam

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Time for action - deleting blog posts

We will modify the code of the Blog Dashboard once again to add a Delete link to each article displayed. Clicking on this link will display a JavaScript confirmation box, and clicking on Yes on that box will delete the article and reload the page:

  1. Open up dashboard.php in your editor. Delete the old code in that file, and add the following code to it:
    <?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; //number of articles to show per page $skip = ($currentPage - 1) * $articlesPerPage; $cursor ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required