Creare impaginazione

Marco Bonanno

Utente Attivo
3 Lug 2012
32
0
6
Ciao ragazzi, ho risolto con lo scorso problema, ma ora ne sorge un altro che sto trovando difficoltà.
Ho provato alcune opzioni per creare l'impaginazione con la semplice numerazione, ma nulla.

Questo è il file index.php

PHP:
<?php include 'templates/header.php'; ?>

<!-- List Pothos -->
<div class="row">
<?php $ASPhoto = new ASPhoto(); ?>
<?php $photo = $ASPhoto->getFilename(); ?>
<?php foreach($photo as $filename): ?>
<div class="col-sm-3 col-md-3">
<div class="post">
<div class="post-img-content">
<a href="show.php?id=<?php echo $filename['photo_id']; ?>"><img src="images/<?php echo e($filename['filename']); ?>" class="img-responsive"/>
<span class="post-title">
<b><i class="icon-time glyphicon glyphicon-time"></i> <?php echo $filename['post_time']; ?></b><br />
<b><i class="icon-user glyphicon glyphicon-user"></i> <?php echo e($filename['posted_by_name']); ?></b>
</a>
</span>
</div>
</div>
</div>
<?php endforeach; ?>
</div>

<?php include 'templates/footer.php'; ?>
<script src="ASLibrary/js/asengine.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="ASLibrary/js/index.js" charset="utf-8"></script>
</body>
</html>


Mentre questo è il file ASPhoto.php

PHP:
/**
 * Photos class.
 */
class ASPhoto {

    /**
     * @var Instance of ASDatabase class itself
     */
    private $db = null;

    /**
     * Class constructor
     */
    function __construct() {
        $this->db = ASDatabase::getInstance();
    }


    /**
     * Inserts photos into database.
     * @param int $userId Id of user who is posting the photo.
     * @param string $filename
     * @return string JSON encoded string that consist of 3 fields:
     * user,filename and postTime
     */
    public function insertFilename($userId, $filename) {
        $user     = new ASUser($userId);
        $userInfo = $user->getInfo();
        $datetime = date("Y-m-d H:i:s");

        $this->db->insert("as_photo",  array(
            "posted_by"      => $user->id(),
            "posted_by_name" => $userInfo['username'],
            "filename"        => strip_tags($filename),
            "post_time"      => $datetime
        ));
        $result = array(
            "user"      => $userInfo['username'],
            "filename"   => stripslashes( strip_tags($filename) ),
            "postTime"  => $datetime
        );
        return json_encode($result);
    }



    /**
     * Return all photos left by one user.
     * @param int $userId Id of user.
     * @return array Array of all user's photos.
     */
    public function getUserPhoto($userId) {
        $result = $this->db->select(
                    "SELECT * FROM `as_photo` WHERE `user_id` = :id",
                    array ("id" => $userId)
                  );

        return $result;
    }


    /**
     * Returns the photo to its ID
     * @param int $id ID photo.
     * @return array Array of all user's photos.
     */
    public function getPhotoById($id) {
        return $this->db->select("SELECT * FROM `as_photo` WHERE `photo_id` = $id");
    }



    /**
     * Return last $limit (default 7) photos from database.
     * @param int $limit Required number of photos.
     * @return array Array of photos.
     */
    public function getFilename($limit = 16) {
        return $this->db->select("SELECT * FROM `as_photo` ORDER BY `post_time` DESC LIMIT $limit");
    }

}


Come dicevo ho provato alcuni script già pronti per l'impaginazione numerica oppure a scroll (che preferisco), ma ho trovato difficoltà sulla giusta sintassi del codice.

Per dare un esempio, come fare per implementare questo seguendo quanto sopra? Devo cominciare togliendo il $limit no?

http://www.sanwebe.com/2013/05/auto-load-records-on-page-scroll

Per prima cosa è corretto (nel mio caso) creare la tabella database del tutorial?
Quindi:

Codice:
CREATE TABLE IF NOT EXISTS `paginate` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(60) NOT NULL,
  `message` text NOT NULL,
  PRIMARY KEY (`id`)
)

Grazie mille a chi mi vorrà aiutare
 

Discussioni simili