Ver Mensaje Individual
  #5 (permalink)  
Antiguo 23/07/2011, 11:52
Avatar de Most
Most
 
Fecha de Ingreso: marzo-2009
Mensajes: 642
Antigüedad: 15 años, 1 mes
Puntos: 6
Respuesta: poner limites a paginador

para no habrir otro hilo, ya he implementado uno, pero como no, hay un problema:

ERROR:
Cita:
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 '0,10' at line 1

Codigo:
Código PHP:
Ver original
  1. <?
  2. //conectamos a la base
  3. $con=mysql_connect("xxx","xxx","xxx");
  4. //Seleccionamos la base
  5. $base="xxx";
  6. mysql_select_db($base,$con);
  7.  
  8. if (!isset($pg))
  9. $pg = 0; // $pg es la pagina actual
  10. $cantidad=10; // cantidad de resultados por página
  11. $inicial = $pg * $cantidad;
  12.  
  13. //hacemos las consultas
  14. $pegar = "select * from noticias order by fecha Desc $inicial,$cantidad";
  15. $cad = mysql_db_query($base,$pegar) or die (mysql_error());
  16.  
  17. $contar = "SELECT * FROM noticias ORDER BY titulo";
  18. $contarok= mysql_db_query($base,$contar);
  19. $total_records = mysql_num_rows($contarok);
  20. $pages = intval($total_records / $cantidad);
  21.  
  22. // Imprimiendo los resultados
  23. while($array = mysql_fetch_array($cad)) {
  24. echo $array['titulo']."<br>";
  25. }
  26.  
  27. // Cerramos la conexión a la base
  28. $con=mysql_close($con);
  29.  
  30. ?>
  31. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  32. <html xmlns="http://www.w3.org/1999/xhtml">
  33. <head>
  34. <link rel="StyleSheet" href="css.css" media="all" type="text/css">
  35. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  36. <title>Documento sin título</title>
  37. <style type="text/css">
  38. </style>
  39. </head>
  40.  
  41. <body>
  42. <div id="cabecera">MENU</div>
  43. <div id="contenedor_2">
  44. <div id="categoria"><div id="contenedor_3"><div id="selecciona_cat"></div></div></div>
  45. </div>
  46. <div id="contenedor">
  47. <div id="contenido_a"></div>
  48. <div id="contenido_b">
  49. <div id="contenedor_9">
  50. <div style="text-align:center" id="menu_izq_a">
  51. URL AMIGAS
  52. </div>
  53. <div style="text-align:center" id="menu_izq_b">
  54.   <a href="#"><p>AQUI CONTENIDO
  55.   </p>
  56.   </a>
  57.   <p>&nbsp;</p>
  58.   <p>&nbsp;</p>
  59.   <p>&nbsp;</p>
  60. </div>
  61. <div id="menu_izq_c"></div>
  62. </div>
  63.  
  64.  
  65.  
  66. <?
  67. while($row=mysql_fetch_array($result))
  68. {
  69. echo '<div id="tit_noticia">';
  70. echo '<div id="contenedor_8"><a href="#">';
  71. echo '<img border="0" style="text-decoration: none;"src="imagenes/icon/favoritos_off/favoritos_off_down.png" id="imagen" ';
  72. echo 'onmouseover="this.src="imagenes/icon/favoritos_off/favoritos_off_up.png"" onmouseout="this.src="imagenes/icon/favoritos_off/favoritos_off_down.png""></a></div>';
  73. echo '<div id="contenedor_4" class="noticia_texto">' .$row[titulo]. '</div></div>';
  74. echo '<div id="contenido_noticia">';
  75. echo '<div id="contenedor_5"><img src="http://img.vidaextra.com/2009/08/ps3-slim-001.jpg" width="177" height="140" /></div>';
  76. echo '<div id="contenedor_6" class="noticia_contenido">';
  77. echo '<p>'.$row[articulo].'</p>';
  78. echo '<p>&nbsp;</p>';
  79. echo '</div>';
  80. echo '</div>';
  81. echo '<div id="stats_noticias"><div id="contenedor_7" class="autor">Noticia publicada por '.$row[autor].'</div></div>';
  82. echo '<div id="espacio"></div>';
  83. }
  84.  
  85.  
  86.  
  87.  
  88. // Creando los enlaces de paginación
  89. echo "<p>";
  90. if ($pg != 0) {
  91. $url = $pg - 1;
  92. echo "<a href='$PHP_SELF?pg=".$url."'>&laquo; Anterior</a>&nbsp;";
  93. } else {
  94. echo " ";
  95. }
  96. for ($i = 0; $i <= $pages; $i++) {
  97. if ($i == $pg) {
  98. if ($i == "0") {
  99. echo "<b> 1 </b>";
  100. } else {
  101. $i = $i+1;
  102. echo "<b> ".$i." </b>";
  103. }
  104. } else {
  105. if ($i == "0") {
  106. echo "<a href=$PHP_SELF?pg=".$i.">1</a> ";
  107. } else {
  108. echo "<a href='$PHP_SELF?pg=".$i."'>";
  109. $i = $i+1;
  110. echo $i."</a>&nbsp;";
  111. }
  112. }
  113. }
  114. if ($pg < $pages) {
  115. $url = $pg + 1;
  116. echo "<a href='$PHP_SELF?pg=".$url."'>Siguiente &raquo;</a>";
  117. } else {
  118. echo " ";
  119. }
  120. echo "</p>";
  121. ?>
  122. </div>
  123. <div id="contenido_c"></div>
  124. </div>
  125. </body>
  126. </html>