Pagination Problem
Posted: Fri Mar 18, 2005 10:11 am
I have this problem with the pagination...
When I'm going to search the page two it returns the page one and it shows all the records...I think the problem is with the TOP because the $length variable stays in 25...the other thing is that I have the code in MySql and now I'm working with MSSQL and I don't know what to do..
Thanks
feyd | Please review how to post code using
Code: Select all
$length = 25;
if(isset($_GET["pag"]))
$start = ($_GET["pag"] * $length) - $length;
else
{
$start = 0;
$pag = 1;
}
if($_GET["pag"] == 0)
{
$start = 0;
$pag = 1;
}
$cantidad = array();
$cons = new BaseDatos;
$cons->connect();
$sql = "select count(*) as numero from sitios_utiles where activo=1 and categoria=$id";
//echo $sql. "-----<br>";
$res = $cons->query($sql);
if($dato = $cons->fetch_row($res)) {
array_push($cantidad,$dato);
}
//print_r($cantidad);
$numero = $cantidad[0][0];
//echo "<br>$sql <br> el numero de noticias es $numero";
$numero_paginas = ceil($numero/$length);
//echo "<br> NUmero de paginas que resultan => " . $numero_paginas;
$cons = new BaseDatos;
$cons->connect();
$sql = "select top $length * from sitios_utiles where activo=1 and categoria=$id order by orden DESC, nombre ASC";
//echo "<br>" . $sql;
$res = $cons->query($sql);
if ($cons->fetch_row($res) > 0){
$hay = "si";
}
if($hay == "si" and $numero_paginas > 1) { ?>
</p>
<div align="center"> <span class="azul_txtblanco">Mas Sitios > </span>
<span class="tabla-general">
<?
for ($i=1; $i<=$numero_paginas; $i++)
{
if ($_GET["pag"] == $i)
echo $i." ";
else { ?>
<a href="<? echo $PHP_SELF ?>?id=<? echo $id ?>&pag=<? echo $i ?>"><? echo $i ?></a>
<? }
}Thanks
feyd | Please review how to post code using
Code: Select all
andCode: Select all
tags. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]