
Saludos.
Tengo el siguiente código:
Código PHP:
<?php
include ('db-cnx.php');
// verificamos si se ha enviado
// alguna variable via GET
$TAMANO_PAGINA = 5;
$pagina = $HTTP_GET_VARS['pagina'];
if ($pagina)
{
$inicio = 0;
$pagina = 1;
}
else {
$inicio = ($pagina - 1) * $TAMANO_PAGINA;
}
if(isset($_GET['id']) && $_GET['categoria']){
// asignamos los valores
// a las variables que usaremos
$cat_ID = $_GET['id'];
$categoria = $_GET['categoria'];
$clausula = "WHERE notCategoriaID = '$cat_ID'";
// tambien armamos el titular de la pagina
$titulo = "Noticias en la categoria $categoria";
}else{
// de lo contrario
// el titulo sera general
$titulo = "Todas las noticias";
}
// armamos la consulta
$sqlQueryNot = mysql_query("SELECT notTitulo, notTexto FROM sn_noticias
WHERE notCategoriaID = '$cat_ID' LIMIT $inicio , $TAMANO_PAGINA")
or die(mysql_error());
$num_total_registros = mysql_num_rows($sqlQueryNot);
$total_paginas = ceil($num_total_registros / $TAMANO_PAGINA);
echo "<h1>$titulo</h1>";
// mostramos las noticias,
// otra vez usando un bucle while
while($rowNot = mysql_fetch_array($sqlQueryNot)){
echo "<h1>$rowNot[notTitulo]</h1>";
echo nl2br($rowNot['notTexto']);
echo "<br>";
}
echo "El número de noticias encontradas: " .$num_total_registros. "<br>";
echo "<br>";
echo "Se muestran páginas de " . $TAMANO_PAGINA . " noticias cada una<br>";
echo "<br>";
echo "Mostrando la página " .$pagina. " de " .$total_paginas. "<p>";
if ($total_paginas > 1)
{
for ($i = 1; $i <= $total_paginas; $i++){
if ($pagina == $i)
echo $pagina . "";
else
echo "<a href='index.php?pagina= . $i '>" . $i . "</a>";
}
}
?>
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-5 , 5' at line 2.