a la hora de mostrar los post con una determinada etiqueta... el paginador funciona en cuanto a la cantidad de registros a mostrar por pagina pero no a la hora de mostrar los mismos... es decir solo muestra los de la primera, de la segunda en adelante reconoce que hay mas registros pero no los muestra y de veras no le hallo el error :C a ver si alguien con mejor ojo me ayuda a encontrar el fallo
aca dejo el codigo:
<!-- PAGINADOR -->
Código PHP:
<?php
/*
Place code to connect to your DB here.
*/
require("soporte/conexiondb.php"); // conectamos a la base de datos
$tag = intval((quitar($_GET['tag'])));
$tbl_name="post"; //nombre de la tabla
$adjacents = 2;
/*
Primero obtenemos el numero total de filas en la tabla.
*/
$query = "SELECT COUNT(*) as num FROM $tbl_name WHERE etiquetas='$tag' ORDER BY id DESC";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages['num'];
/* variables a utilizar para la consulta. */
$targetpage = "etiquetas.php"; //nombre del archivo
$limit = 1; //Cantidad limite de registros a mostrar por cada pagina
$page = "http://localhost/blog/php/etiquetas.php?tag='".$tag."'";
if(isset($_GET["page"])){
$page = (int)$_GET["page"];
$start = ($page - 1) * $limit; //primer item a mostrar
}else{
$start = 0; //Si no hay registros existentes, empezar pagina en 0
}
/* Realizamos y obtenemos datos de la consulta. */
$sql = mysql_query("SELECT * FROM $tbl_name WHERE etiquetas='$tag' ORDER BY id 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
/*
Now we apply our rules and draw the pagination object.
We're actually saving the code to a variable in case we want to draw it more than once.
*/
$pagination = "";
if($lastpage > 1)
{
$pagination .= "<div class=\"pagination\">";
//previous button
if ($page > 1)
$pagination.= "<a href=\"$targetpage?page=$prev\"> <span class=\"icon-reply\" alt=\"Atras\"> </span></a>";
else
$pagination.= "<span class=\"icon-reply\" alt=\"Atras\"> </span>";
# $pagination.= "<span class=\"disabled\">« previous</span>";
//pages
if ($lastpage < 7 + ($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 < 4 + ($adjacents * 2); $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=$targetpage?page=$lpm1>$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
}
//in middle; hide some front and some back
elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
{
$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
$pagination.= "...";
for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
{
if ($counter == $page)
$pagination.= "<span class=\"current\">$counter</span>";
else
$pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";
}
$pagination.= "...";
$pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>";
$pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";
}
//close to end; only hide early pages
else
{
$pagination.= "<a href=\"$targetpage?page=1\">1</a>";
$pagination.= "<a href=\"$targetpage?page=2\">2</a>";
$pagination.= "...";
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>";
}
}
}
//next button
if ($page < $counter - 1)
$pagination.= "<a href=\"$targetpage?page=$next\"><span class=\"icon-forward\" alt=\"Siguiente\"></span></a>";
else
$pagination.= "<span class=\"icon-forward\" alt=\"Siguiente\"></span>";
# $pagination.= "<span class=\"disabled\">next »</span>";
$pagination.= "</div>\n";
}
?>
<?php
//si no hay registros existentes, se le notifica al usuario
if ($total_pages == 0){
?>
<script type="text/javascript">
alert("No se ha registrado ningún Post hasta el momento...");
</script>
<?php
//de lo contrario, se procede a mostrar los resultados.
} else {
while ($row=mysql_fetch_array($sql)) {
?>
<!-- Se muestra el POST-->
<section id="articulo_seis">
<h1> <?php echo $row['titulo']; ?></h1>
<?php echo '<img src="'.$row['imagen'] .'">'?>
<article>
<p>
<?php echo substr($row['contenido'], 0,380)."..."; ?> <a href="post.php?n=<?php echo $row['id']; ?>" class="more"> Leer más</a>
</p>
</article>
<h6> <?php echo "Por ".$row['autor']; ?> <?php echo "el ".$row['dia']."/".$row['mes']."/".$row['anio'] ." a las ".$row['hora']; ?> </h6>
</section>
<?php
}
} echo $pagination;
?>