I have a page for displaying items from database limited to 20 records the other records should be displayed on the next page, 20 items per page, and so on here is the code for displaying the last 20 items.
<?php
require_once '../Model/Connexion.php';
$c = new Connexion();
$results = $c->query("select * from annonce limit 20 ");
$rows = $c->resultset(); ?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Ads display</title>
</head>
<body>
<div id="Wraper">
<div id="Middle">
<div class="Left">
<div class="Content FCKeditor">
<div class="Pagination">
<span class="Fright">Page 1
<a href="page.php?page=<?php echo $number?>"> | Next </a></span>
<span class="Fleft">Showing 1 to 20 jobs of <?php echo $c->rowCount()?></span>
</div>
<div class="Joblist">
<?php foreach($rows as $r) { ?>
<p class="Title">
<span class="Ref"></span>
<a href="details.php?id=<?php echo($r['id_annonce']) ?>">
<?php echo($r['poste']); ?></a></p>
<p class="Date"><span class="Fright"><?php echo($r['type_contrat']); ?></span>
<span><a href="client.php" class="Sectorbtn"><?php echo($r['client']); ?></a></span></p>
<p style="text-align:justify;"><?php echo($r['desc_annonce']); ?></p>
<p class="More">
<a href="details.php?id=<?php echo($r['id_annonce']) ?>">View more</a>
</p>
<?php }?>
</div>
<div class="Pagination">
<span class="Fright">Page 1<a href="page.php?page=<?php echo $number?>"> | Next </a></span>
<span class="Fleft">Showing 1 to 20 jobs of <?php echo $c->rowCount()?></span>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
I wish to display the others itemps on an ordred pages could you help me ?
Basically, you need 2 requests :
A request to count the total number of jobs :
SELECT COUNT(*) FROM annonce
A request to give you X jobs starting from (n-1)*X to be included in the nth page. Example for the 4th page :
SELECT * FROM annonce LIMIT 60, 20