Need some help with the best way to paginate through these results...

So I’m quite new to OOP/MVC/Frameworks, I’ve decided to mess around with the Huge] user authentication script. However, when trying to query the database I’m getting quite stumped figuring out the best way to paginate through the results.

My model:

<?php

class ShareModel
{
    /**
     * Get all shares
     * @return array an array with several objects (the results)
     */
    public static function getAllShares() {

        $database = DatabaseFactory::getFactory()->getConnection();

        $sql = "SELECT * FROM shares ORDER BY id";

        $query = $database->prepare($sql);

        $query->execute();

        return $query->fetchAll();

    }
    
}

My view:

<?php if ($this->shares) { ?> <table class="note-table"> <thead> <tr> <td>Id</td> <td>Title</td> </tr> </thead> <tbody> <?php foreach($this->shares as $key => $value) { ?> <tr> <td><?= $value->id; ?></td> <td><?= htmlentities($value->share_title); ?></td> </tr> <?php } ?> </tbody> </table> <?php } else { ?> <div>No shares yet. Create some !</div> <?php } ?>

Could anyone nudge me in the right direction?

Quick and easy? print_r on the results to see what comes back.

Sponsor our Newsletter | Privacy Policy | Terms of Service