I am creating a page that contains pagination, but I have a problem, the pagination works perfect but it brings the oldest records first and I would like the current records to be displayed first, could anyone help me?
Here is the code I created as an example below:
<?php
mysql_connect("localhost","root","root");
mysql_select_db("paginacao");
?>
<table border="1" cellpadding="10" cellspacing="10">
<tr>
<th width="60">ID</th>
<th width="150">Descrição</th>
<th width="80">Valor</th>
</tr>
<?php
$limite = 3;
$sql_count = mysql_query("SELECT COUNT('id') FROM produtos;");
$sql_result = ceil(mysql_result($sql_count, 0) / $limite);
$pg = (isset($_GET["pg"])) ? (int) $_GET["pg"] : 1;
$start = ($pg - 1) * $limite;
$sql_produtos = mysql_query("SELECT * FROM produtos LIMIT $start, $limite");
while ($lh = mysql_fetch_array($sql_produtos)){
?>
<tr>
<td><?php echo $lh['id'] ?></td>
<td><?php echo utf8_encode($lh['descricao']); ?></td>
<td align="right"><?php echo $lh['valor'] ?></td>
</tr>
<?php } ?>
<tr>
<td align="center" colspan="3" >
<div class="container">
<ul class="pagination">
<?php
if ($sql_result > 1 && $pg<=$sql_result) {
for($i=1; $i <= $sql_result; $i++){
echo "<li><a href='?pg=$i'> $i </a></li>";
}
}
?>
</ul>
</div>
</td>
</tr>
</table>
<?php echo isset($_GET["pg"]); ?>
</body>