A plain and simple one in purpose to learn from
$per_page=10;
//put FROM and WHERE parts into separate variable
$from_where="FROM table WHERE filter=1";
//getting total number of records
$res=mysql_query("SELECT count(id) ".$from_where);
$row=mysql_fetch_row($res);
$total_rows=$row[0];
//Process GET variables to get $start value for LIMIT
if (isset($_GET['page'])) $CUR_PAGE=($_GET['page']); else $CUR_PAGE=1;
$start=abs(($CUR_PAGE-1)*$per_page);
//getting records from database into array
$query="SELECT * $from_where ORDER BY date DESC LIMIT $start,$per_page";
$res=mysql_query($query);
while ($row=mysql_fetch_array($res)) $DATA[++$start]=$row;
//Getting page URL without query string
$uri=strtok($_SERVER['REQUEST_URI'],"?")."?";
//create a new query string without a page variable
if (isset($_GET['page'])) unset($_GET['page']);
if (count($_GET)) {
foreach ($_GET as $k => $v) {
if ($k != "page") $uri.=urlencode($k)."=".urlencode($v)."&";
}
}
//getting total number of pages and filling an array with links
$num_pages=ceil($total_rows/$per_page);
for($i=1;$i<=$num_pages;$i++) $PAGES[$i]=$uri.'page='.$i;
//and here goes a simple template
?>
Total records: =$total_rows?>
foreach ($DATA as $i => $row): ?>
=$i?>. =$row['title']?>
endforeach ?>
Pages:
foreach ($PAGES as $i => $link): ?>
if ($i == $CUR_PAGE): ?>
=$i?>
else: ?>
=$i?>
endif ?>
endforeach ?>