Paginacion php (Siguiente - Atras)

  • Autor Autor aldairs
  • Fecha de inicio Fecha de inicio
A

aldairs

Beta
Verificado por Whatsapp
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
No puedo hacer la paginacion :S trato y trato y nada nose si me podrian ayudar?
Paginacion oosea de poner siguiente y atras me entienden? lo rojo es el codigo pero no conecta? ayudenme

<?php

require "connect.php";
require "suggestion.class.php";

$RegistrosAMostrar=8;
if(isset($_GET['pag'])){
$RegistrosAEmpezar=($_GET['pag']-1)*$RegistrosAMostrar;
$PagAct=$_GET['pag'];
}else{
$RegistrosAEmpezar=0;
$PagAct=1;
}
$id=(int) $_GET['id'];

if($id == ''){
$NroRegistros=mysql_num_rows(mysql_query("SELECT * FROM suggestions",$conexion));}
else
{$NroRegistros=mysql_num_rows(mysql_query("SELECT * FROM suggestions WHERE id = $id",$conexion));}


$PagAnt=$PagAct-1;
$PagSig=$PagAct+1;
$PagUlt=$NroRegistros/$RegistrosAMostrar;
$Res=$NroRegistros%$RegistrosAMostrar;


// If the request did not come from AJAX, exit:
if($_SERVER['HTTP_X_REQUESTED_WITH'] !='XMLHttpRequest'){
exit;
}

// Converting the IP to a number. This is a more effective way
// to store it in the database:

$ip = sprintf('%u',ip2long($_SERVER['REMOTE_ADDR']));

if($_GET['action'] == 'vote'){

$v = (int)$_GET['vote'];
$id = (int)$_GET['id'];

if($v != -1 && $v != 1){
exit;
}

// Checking to see whether such a suggest item id exists:
if(!$mysqli->query("SELECT 1 FROM suggestions WHERE id = $id")->num_rows){
exit;
}

// The id, ip and day fields are set as a primary key.
// The query will fail if we try to insert a duplicate key,
// which means that a visitor can vote only once per day.

$mysqli->query("
INSERT INTO suggestions_votes (suggestion_id,ip,day,vote)
VALUES (
$id,
$ip,
CURRENT_DATE,
$v
)
");

if($mysqli->affected_rows == 1)
{
$mysqli->query("
UPDATE suggestions SET
".($v == 1 ? 'votes_up = votes_up + 1' : 'votes_down = votes_down + 1').",
rating = rating + $v
WHERE id = $id
");
}

}
else if($_GET['action'] == 'submit'){

if(get_magic_quotes_gpc()){
array_walk_recursive($_GET,create_function('&$v,$k','$v = stripslashes($v);'));
}

// Stripping the content
$_GET['content'] = htmlspecialchars(strip_tags($_GET['content']));

if(mb_strlen($_GET['content'],'utf-8')<3){
exit;
}

$mysqli->query("INSERT INTO suggestions SET suggestion = '".$mysqli->real_escape_string($_GET['content'])."'");

// Outputting the HTML of the newly created suggestion in a JSON format.
// We are using (string) to trigger the magic __toString() method of the object.

echo json_encode(array(
'html' => (string)(new Suggestion(array(
'id' => $mysqli->insert_id,
'suggestion' => $_GET['content']
)))
));
}


if($Res>0) $PagUlt=floor($PagUlt)+1;
if($id == ''){
if($PagAct>1) echo "<a style='cursor: pointer; cursor: hand;' href='".$scripturl."?pag=$PagAnt'><b>« Anterior</b></a>";
if($PagAct>1) echo " || ";
if($PagAct<$PagUlt) echo "<a style='cursor: pointer; cursor: hand;' href='".$scripturl."?pag=$PagSig'><b>Siguiente »</b></a>";
}else
{
if($PagAct>1) echo "<a style='cursor: pointer; cursor: hand;' href='". $scripturl ."?pag=$PagAnt&id=$id'><b>« Anterior</b></a>";
if($PagAct>1) echo " || ";
if($PagAct<$PagUlt) echo "<a style='cursor: pointer; cursor: hand;' href='". $scripturl ."?pag=$PagSig&id=$id'><b>Siguiente »</b></a>";
}



?>
 
da algun error o algo ?

a simple vista me parece que le falta la parte de LIMIT y OFFSET o LIMIT con dos parámetros.
 
Como dice ElPlayer te falta el LIMIT, en este caso seria algo como LIMIT $RegistrosAEmpezar, $RegitrosATerminar
Siendo $RegistrosATerminar = $RegistrosAEmpezar + $RegistrosAMostrar
 
Puedes cambiar de script de paginación.
 
Atrás
Arriba