Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/07/2012, 05:42
rai0d
 
Fecha de Ingreso: noviembre-2005
Mensajes: 43
Antigüedad: 18 años, 5 meses
Puntos: 2
valor de variable se pierde al paginar en php

tengo el siguiente código, el sistema de navegación funciona perfectamente en que paso

?var=palabra -> me muestra los registros correctos

pero cuando pasa en la siguiente pagina siguiente /?page=2?var=palabra

se me pierde la variable y se pierde el filtro mostrando solo los registros

alguien sabe donde se encuentra la el error del código?

saludos


Adjunto el código:

$adjacents = 1;

$query = "SELECT COUNT(*) as num FROM tabla";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];

/* Setup vars for query. */
$targetpage = ""; //your file name (the name of this file)
$limit = 10; //how many items to show per page
$var = $_GET['var'];

if($page)
$start = ($page - 1) * $limit; //first item to display on this page

else
$start = 0; //if no page var is given, set start to 0


/* Get data. */
$sql = "SELECT * FROM tabla WHERE `texto` LIKE '%$var%' order by created_at DESC LIMIT $start, $limit";
$result = mysql_query($sql);

/* Setup page vars for display. */
if ($page == 0) $page = 1; //if no page var is given, default to 1.
$prev = $page - 1; //previous page is page - 1
$next = $page + 1; //next page is page + 1
$lastpage = ceil($total_pages/$limit); //lastpage is = total pages / items per page, rounded up.
$lpm1 = $lastpage - 1; //last page minus 1
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class=\"pagination\">";
//previous button
if ($page > 1)
$pagination.= "<a href=\"$targetpage?page=$prev?var=$var\">« Anterior </a>";
else
$pagination.= "<span class=\"disabled\">« Anterior </span>";
//pages
if ($lastpage < 2 + ($adjacents * 2)) //not enough pages to bother breaking it up
{
for ($counter = 1; $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
}

elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some
{
//close to beginning; only hide later pages
if($page < 1 + ($adjacents * 2))
{
for ($counter = 1; $counter < 2 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter </span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter?var=$var\">$count er </a>";
}
}
//in middle; hide some front and some back
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{

for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\"> $counter </span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter?var=$var\"> $counter </a>";
}
}
//close to end; only hide early pages
else
{
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
}
}
//siguiente
if ($page < $counter - 1)
$pagination.= "<a href=\"$targetpage?page=$next\?var=$var\"> Siguiente » </a>";
else
$pagination.= "<span class=\"disabled\"> Siguiente » </span>";
$pagination.= "</div>\n ";
}
while($row = mysql_fetch_array($result))
{

// Your while loop here echo "<tr>";
echo "<td VALIGN='top'><img src =\"" . $row['profile_image_url']. "\" width='48' height='48'><tr></td> ";
echo "<td VALIGN='top'>$row[name]</td>";
echo "</tr>";

}
?>

<?=$pagination?>