如何在下一页显示成功记录?

时间:2014-07-10 12:32:06

标签: php mysql pdo fetch

我有一个页面,用于显示数据库中的项目,限制为20条记录 其他记录应显示在下一页,每页显示20个项目,依此类推 这是显示最后20个项目的代码。

<?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>

我想在ordred页面上显示其他的迭代你能帮帮我吗?

1 个答案:

答案 0 :(得分:0)

基本上,您需要2个请求:

计算工作总数的请求:

SELECT COUNT(*) FROM annonce

从第(n-1)* X开始为您提供X作业的请求将包含在第n页中。 第4页的示例:

SELECT * FROM annonce LIMIT 60, 20