PHP Classes

Class?

Recommend this page to a friend!

      Simple Pagination Class  >  All threads  >  Class?  >  (Un) Subscribe thread alerts  
Subject:Class?
Summary:Shorter method without class
Messages:2
Author:Frank Herget
Date:2010-01-31 11:55:50
Update:2010-02-01 01:10:08
 

  1. Class?   Reply   Report abuse  
Picture of Frank Herget Frank Herget - 2010-01-31 11:55:50
Why a class for it? You can write this in 3 min for any resultset.

define("MAX_RESULTS_PER_PAGE","5");
$page = intval($_GET['page']);
if(!$page || $page < 1){
$page = 1;
}
$show = MAX_RESULTS_PER_PAGE * ($page - 1);
$end = $show + MAX_RESULTS_PER_PAGE;
$limit = "$show,$end";

// example link directory
$link = new webLink();
$cat = $link->getLinkCategory($id);
//
$totalLinks = $link->getTotalFromCategory($cat);
$totalPages = ceil($totalLinks / MAX_RESULTS_PER_PAGE);
$res = $link->getLinksByCategory($cat, 'ASC', $limit );

// output
<?php if($totalPages > 1){ ?>
<div class="clear"></div>
<div class="pagination"><?php for($i=1;$i<=$totalPages;$i++){ echo "<a href=\"linkcategory/$cat/$i/\">$i</a> "; } ?></div>
<?php } ?>

  2. Re: Class?   Reply   Report abuse  
Picture of Jay Gilford Jay Gilford - 2010-02-01 01:10:08 - In reply to message 1 from Frank Herget
Of course you can write it! The idea of a class is to minimise the hassle you have writing code repeatedly. I mean what is easier, writing 5 or six simple lines or writing all that that you've just written. Plus you've got what I'd call poor links too