so, i am newbie in php development, i want to create a pagination with php pdo and sql server, first page works great, but other pages from pagination not work (sorry for my english, i am from brazil)
follows my code
<?php
require 'conn.php';
$pdo = dbConnect();
$limite = 10;
$pg = (isset($_GET['pg'])) ? (int)$_GET['pg'] : 1;
$inicio = ($pg * $limite) - $limite;
$sql = "SELECT * FROM ( SELECT *, ROW_NUMBER() OVER (ORDER BY ID_USUARIO) as row FROM tbl_usuario) a WHERE row between ".$inicio." and ".$limite."";
try {
$query = $pdo->prepare($sql);
$query->execute();
} catch (PDOexception $error_sql){
echo 'Erro ao retornar os Dados.'.$error_sql->getMessage();
}
while($linha = $query->fetch(PDO::FETCH_ASSOC)){ ?>
<?php
echo $linha['NOME'].'</br>';
?>
<?php }
$sql_Total = 'SELECT ID_USUARIO FROM tbl_usuario';
try {
$query_Total = $pdo->prepare($sql_Total);
$query_Total->execute();
$query_result = $query_Total->fetchAll(PDO::FETCH_ASSOC);
$query_count = $query_Total->rowCount(PDO::FETCH_ASSOC);
$qtdPag = ceil($query_count/$limite);
} catch (PDOexception $error_Total){
echo 'Erro ao retornar os Dados. '.$error_Total->getMessage();
}
echo "<div class='relax h30'></div>";
echo '<a href="teste?pg=1">PRIMEIRA PÁGINA</a> ';
echo '<ul id="paginacao">';
echo '<li><a class="anterior" href="teste?pg=1">Anterior</a></li>';
if($qtdPag > 1 && $pg <= $qtdPag){
for($i = 1; $i <= $qtdPag; $i++){
if($i == $pg){
echo "<li><a class='ativo'>".$i."</a></li>";
} else {
echo "<li><a href='teste?pg=$i'>".$i."</a></li>";
}
}
}
echo "<li><a class='proxima' href='teste?pg=$qtdPag'>Próxima</a></li>";
?>