Paginating results

Hi

I am trying to write a script to paginate results
the problem is that this script just return something
after the second page the first do not return nothing.
The other problem is that the script just add the next
set of results at the end of the old set of results,
instead of paginate to them.

<?php
// Database Connection
include 'db.php';

// If current page number, use it
// if not, set one!
if(!isset($_GET['page'])){
$page =3D 1;
} else {
$page =3D $_GET['page'];
}

// Define the number of results per page
$max_results =3D 10;

// Figure out the limit for the query based
// on the current page number.
$from =3D (($page * $max_results) - $max_results);

// Perform SQL query on only the current page
number's results
$sql =3D pg_query("SELECT * FROM paginar LIMIT $from
OFFSET $max_results"); //LIMIT $pagesize OFFSET
$offset

while($row =3D pg_fetch_array($sql)){
// Build your formatted results here.
echo $row['title']."
";
}

// Figure out the total number of results in DB:
$total_results =3D pg_result(pg_query("SELECT COUNT(*)
as Num FROM paginar"),0);

// Figure out the total number of pages. Always round
up using ceil()
$total_pages =3D ceil($total_results / $max_results);

// Build Page Number Hyperlinks
echo "<center>Selecione uma p=E1gina
";

// Build Previous Link
if($page > 1){
$prev =3D ($page - 1);
echo "<a
href=3D\"".$_SERVER['PHP_SELF']."?page=3D$prev\"><<Previous</a> ";

}

for($i =3D 1; $i <=3D $total_pages; $i++){
if(($page) =3D=3D $i){
echo "$i ";
} else {
echo "<a
href=3D\"".$_SERVER['PHP_SELF']."?page=3D$i\">$i</a> ";

}
}

// Build Next Link
if($page < $total_pages){
$next =3D ($page + 1);
echo "<a
href=3D\"".$_SERVER['PHP_SELF']."?page=3D$next\">Next>></a>";

}
echo "</center>";
?>

=3D=3D=3D=3D=3D
=C2ngelo Marcos Rigo
AMR Inform=E1tica
(51) 3348 0870
Rua Pe. Alois Kades 400/210
Porto Alegre /RS/Brasil
http://amr.freezope.org
angelo_rigo [at] yahoo.com.br



____________________________________________________________ ___________
Yahoo! Mail
Mais espa=E7o, mais seguran=E7a e gratuito: caixa postal de 6MB, antiv=ED=
rus, prote=E7=E3o contra spam.
http://br.mail.yahoo.com/

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend
angelo_rigo [ Fr, 18 Juli 2003 16:34 ] [ ID #46422 ]
Datenbanken » gmane.comp.db.postgresql.php » Paginating results

Vorheriges Thema: postgreSQL web form; Security
Nächstes Thema: Vexing PHP problem - browser hangs.