Paginating results

Paginating results

am 18.07.2003 16:34:05 von angelo_rigo

Hi=20

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.

// Database Connection=20
include 'db.php';=20

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

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

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

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

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

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

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

// Build Page Number Hyperlinks=20
echo "

Selecione uma p=E1gina
";=20

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

}=20

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

}=20
}=20

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

}=20
echo "
";=20
?>=20

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


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

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend