php - How do I Paginate my CMS -


i've been following build cms in afternoon tutorial @ http://www.elated.com/articles/cms-in-an-afternoon-php-mysql/ .

the cms works great thing it's lacking pagination. article archive displays list of of articles in database, want able separate these pages. i've attempted few times can never seem work. clicking on next page link brings me homepage.

i apreciate help

code:

config.php

<?php ini_set( "display_errors", true );  date_default_timezone_set("europe/lisbon" );   define( "db_dsn", "mysql:host=localhost;dbname=cms" );  define( "db_username", "username" ); define( "db_password", "password" ); define( "class_path", "classes" );  define( "template_path", "templates" );  define( "homepage_num_articles", 5 );  define( "admin_username", "admin" );  define( "admin_password", "mypass" ); require( class_path . "/article.php" );     function handleexception( $exception ) {    echo "sorry, problem occurred. please try later.";  error_log( $exception->getmessage() ); }     set_exception_handler( 'handleexception' ); ?> 

archive.php

<?php include "templates/include/header.php" ?>        <h1>article archive</h1>        <ul id="headlines" class="archive">  <?php foreach ( $results['articles'] $article ) { ?>          <li>           <h2>             <span class="pubdate"><?php echo date('j f y', $article->publicationdate)?></span><a href=".?action=viewarticle&amp;articleid=<?php echo $article->id?>"><?php echo htmlspecialchars( $article->title )?></a>           </h2>           <p class="summary"><?php echo htmlspecialchars( $article->summary )?></p>         </li>  <?php } ?>        </ul>        <p><?php echo $results['totalrows']?> article<?php echo ( $results['totalrows'] != 1 ) ? 's' : '' ?> in total.</p>        <p><a href="./">return homepage</a></p>  <?php include "templates/include/footer.php" ?> 

article.php

<?php  /**  * class handle articles  */  class article {   public $id = null;    public $publicationdate = null;    public $title = null;    public $summary = null;    public $content = null;     public function __construct( $data=array() ) {     if ( isset( $data['id'] ) ) $this->id = (int) $data['id'];     if ( isset( $data['publicationdate'] ) ) $this->publicationdate = (int) $data['publicationdate'];     if ( isset( $data['title'] ) ) $this->title = preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-za-z0-9()]/", "", $data['title'] );     if ( isset( $data['summary'] ) ) $this->summary = preg_replace ( "/[^\.\,\-\_\'\"\@\?\!\:\$ a-za-z0-9()]/", "", $data['summary'] );     if ( isset( $data['content'] ) ) $this->content = $data['content'];   }     public function storeformvalues ( $params ) {      // store parameters     $this->__construct( $params );      // parse , store publication date     if ( isset($params['publicationdate']) ) {       $publicationdate = explode ( '-', $params['publicationdate'] );        if ( count($publicationdate) == 3 ) {         list ( $y, $m, $d ) = $publicationdate;         $this->publicationdate = mktime ( 0, 0, 0, $m, $d, $y );       }     }   }     public static function getbyid( $id ) {     $conn = new pdo( db_dsn, db_username, db_password );     $sql = "select *, unix_timestamp(publicationdate) publicationdate articles id = :id";     $st = $conn->prepare( $sql );     $st->bindvalue( ":id", $id, pdo::param_int );     $st->execute();     $row = $st->fetch();     $conn = null;     if ( $row ) return new article( $row );   }     public static function getlist( $numrows=1000000, $order="publicationdate desc" ) {     $conn = new pdo( db_dsn, db_username, db_password );     $sql = "select sql_calc_found_rows *, unix_timestamp(publicationdate) publicationdate articles             order " . mysql_escape_string($order) . " limit :numrows";      $st = $conn->prepare( $sql );     $st->bindvalue( ":numrows", $numrows, pdo::param_int );     $st->execute();     $list = array();      while ( $row = $st->fetch() ) {       $article = new article( $row );       $list[] = $article;     }      // total number of articles matched criteria     $sql = "select found_rows() totalrows";     $totalrows = $conn->query( $sql )->fetch();     $conn = null;     return ( array ( "results" => $list, "totalrows" => $totalrows[0] ) );   }   ?> 

you need modify code $_get page number , use limit , offset in query

you can see example

http://www.tutorialspoint.com/php/mysql_paging_php.htm


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -