Page 1 of 1

Pagination Problem

Posted: Fri Mar 18, 2005 10:11 am
by freemojorisin
I have this problem with the pagination...

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 > &nbsp;&nbsp;&nbsp;</span> 
  <span class="tabla-general">
  <?
	    for ($i=1; $i<=$numero_paginas; $i++)	
		{ 
		  if ($_GET["pag"] == $i)						
           echo $i."&nbsp;"; 
          else { ?>
            <a href="<? echo $PHP_SELF ?>?id=<? echo $id ?>&pag=<? echo $i ?>"><? echo $i ?></a>&nbsp; 
          <? } 
  	    }
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

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Fri Mar 18, 2005 10:28 am
by anjanesh
Just a note : If Line 2 evaluates to false, Line 10 will give an error