如何能让如下代码实现如下图一样的分页,每页显示20,如下图不要思路,需要代码完整代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<?php 
  ini_set('date.timezone','Asia/Shanghai');

$link=mysql_connect("127.0.0.1","root","12345678");   
 if(!$link) echo "数据库没有连接成功!";   
//else echo "连接成功!";   
mysql_select_db("busap", $link);          //选择数据库  
if($_REQUEST['submit']!=""){
   if($_REQUEST['xianlu']!=""){
if($_REQUEST['select']=="gzxl"){
//按线路查询
$q = "SELECT * FROM `guzhang` where linename like '%{$_REQUEST['xianlu']}%'";  
}else if($_REQUEST['select']=="wwx"){
//查未维修
$q = "SELECT * FROM `guzhang` where zhuangtai=0";   
}else if($_REQUEST['select']=="ywx"){
//查已维修
$q = "SELECT * FROM `guzhang` where zhuangtai=1";  
}
mysql_query("SET NAMES GB2312"); //防止乱码
$rs = mysql_query($q); //获取数据集fin
$assoc= mysql_num_rows($rs);///影响的行数 , 原来用了mysql_fetch_assoc
$row=mysql_fetch_array($rs); //只需要补充回这一行. 
if(!$rs){die("Valid result!");}
}
    }
?>      
<form id="form1" name="form1" method="post" action="">
  <label>
<div align="center">
  <select name="select">
    <option value="gzxl">故障线路</option>
    <option value="wwx">未维修</option>
<option value="ywx">已维修</option>
  </select>
  &nbsp;&nbsp;
  <label>
  <input name="xianlu" type="text" size="10" />
  </label>
  &nbsp;&nbsp;
    <input type="submit" name="submit" value="查询" />
  </div>
  </label>
</form><table width="72%" border="1" align="center">
  <tr>
    <td width="6%" height="22" nowrap="NOWRAP"><div align="center">线路</div></td>
    <td width="8%" nowrap="NOWRAP"><p align="center">时间</p>    </td>
    <td width="6%" nowrap="NOWRAP"><div align="center">车辆自编号</div></td>
    <td width="7%" nowrap="NOWRAP"><div align="center">车牌号</div></td>
    <td width="10%" nowrap="NOWRAP"><div align="center">故障定位</div></td>
    <td width="9%" nowrap="NOWRAP"><div align="center">故障现象</div></td>
    <td width="9%" nowrap="NOWRAP"><div align="center">处理建议</div></td>
    <td width="6%" nowrap="NOWRAP"><div align="center">报修人</div></td>
    <td width="7%" nowrap="NOWRAP"><div align="center">维修状态</div></td>
    <td width="9%" nowrap="NOWRAP"><div align="center">维修人</div></td>
    <td width="10%" nowrap="NOWRAP"><div align="center">维修日期</div></td>
    <td width="13%" nowrap="NOWRAP"><div align="center">维修过程</div></td>
    <td width="13%" nowrap="NOWRAP"><div align="center">操作</div></td>
  </tr>
  <?php 
  if($_REQUEST['submit']!="")
 {
 do { 
?>
<?php
    if($row[zhuangtai]=="0"){
$leixing="未维修";
}elseif($row[zhuangtai]=="1"){
$leixing="已维修";
}else{
$leixing="";
}
?>
  <tr>
    <td height="47" nowrap="NOWRAP"><div align="center"><?php echo $row[linename]; ?></div></td>
    <td nowrap="NOWRAP"><div align="center"><?php echo (date('Y-m-d',$row[time])); ?></div></td>
    <td nowrap="NOWRAP"><div align="center"><?php echo $row[busname]; ?></div></td>
    <td nowrap="NOWRAP"><div align="center"><?php echo $row[chepaihao]; ?></div></td>
    <td nowrap="NOWRAP"><div align="center"><?php echo $row[dingwei]; ?></div></td>
    <td nowrap="NOWRAP"><div align="center"><?php echo $row[xianxiang]; ?></div></td>
    <td nowrap="NOWRAP"><div align="center"><?php echo $row[jianyi]; ?></div></td>
    <td nowrap="NOWRAP"><div align="center"><?php echo $row[baoxiuren]; ?></div></td>
    <td nowrap="NOWRAP"><div align="center"><?php echo $leixing; ?></div></td>
    <td nowrap="NOWRAP"><div align="center"><?php echo $row[weixiuren]; ?></div></td>
    <td nowrap="NOWRAP"><div align="center"><?php echo (date('Y-m-d',$row[weixiutime])); ?></div></td>
    <td nowrap="NOWRAP"><div align="center"><?php echo $row[guocheng]; ?></div></td>
    <td nowrap="NOWRAP"><div align="center"><form id="form2" name="form2" method="post" action="">   
  <input name="button" type="button" onclick=" window.location='guzhang_weixiu.php?wxry=<?php echo $row[id]; ?>&weixiu=1&id=<?php echo $row[id]; ?>'" value="维修" />
  &nbsp;&nbsp;
  <input name="del" type="button" onclick=" window.location='guzhang_del.php?id=<?php echo $row[id]; ?>'" value="删除" />     
    </form> </div></td>
  </tr>
  <?php }while($row=mysql_fetch_array($rs)); }?>
</table>
</body>
</html>

解决方案 »

  1.   

    参考:http://www.oschina.net/code/snippet_162279_5852
      

  2.   

    sql查询控制一下就OK了
    SELECT 字段 
    FROM   表名
    LIMIT 页码 , 20
      

  3.   

    分页显示的关键技术:
    sql 语句中的limit的运用.
      

  4.   

    分页代码网上一把一把的 
    <?php
    $perNumber=10; //每页显示的记录数
    $page=$_GET['page']; //获得当前的页面值
    $count=mysql_query("select count(*) from user"); //获得记录总数
    $rs=mysql_fetch_array($count); 
    $totalNumber=$rs[0];
    $totalPage=ceil($totalNumber/$perNumber); //计算出总页数
    if (!isset($page)) {
     $page=1;
    } //如果没有值,则赋值1
    $startCount=($page-1)*$perNumber; //分页开始,根据此方法计算出开始的记录
    $result=mysql_query("select * from user limit $startCount,$perNumber"); //根据前面的计算出开始的记录和记录数
    while ($row=mysql_fetch_array($result)) {
     echo "user_id:".$row[0]."<br>";
     echo "username:".$row[1]."<br>"; //显示数据库的内容
    }
    if ($page != 1) { //页数不等于1
    ?>
    <a href="fenye.php?page=<?php echo $page - 1;?>">上一页</a> <!--显示上一页-->
    <?php
    }
    for ($i=1;$i<=$totalPage;$i++) {  //循环显示出页面
    ?>
    <a href="fenye.php?page=<?php echo $i;?>"><?php echo $i ;?></a>
    <?php
    }
    if ($page<$totalPage) { //如果page小于总页数,显示下一页链接
    ?>
    <a href="fenye.php?page=<?php echo $page + 1;?>">下一页</a>
    <?php

    ?>
      

  5.   

    就是利用数据库中的limit
      

  6.   

    数据少的情况下最简单的用limit,大数据的话,这个性能就跟不上了。
      

  7.   

    PHP分页显示示例
    //导入数据库连接conn/conn.php
    <?php
     $conn=mysql_connect("localhost","root","root"); //连接数据库服务器
     mysql_select_db("db_forumm",$conn); //连接指定的数据库
     mysql_query("set names gb2312"); //对数据库中的编码格式进行转换,避免出现中文乱码的问题
    ?>
    //显示数据文件信息
    <?php session_start(); include("conn/conn.php"); 
    if ($page=="") {$page=1;};if ($link_type=="") {$link_type=0;};
    ?>
    <link rel="stylesheet" type="text/css" href="css/sow_type_up.css">
    <table width="300" align="center">
     <?php 
       if($page){
        $page_size=8;
      $number=0;
        $query="select count(*) as total from tb_photo" ;
    $result=mysql_query($query);
    $message_count=mysql_result($result,0,"total");
        $page_count=ceil($message_count/$page_size);
        $offset=($page-1)*$page_size;
    $query_2=mysql_query("select up_id,pictype, picpath, picname, upname, uptime from tb_photo where level=0 order by up_id desc limit $offset, $page_size");
    while($myrow_2=mysql_fetch_array($query_2)){
    if(($number % 2) == 0){
    ?>
       <tr> 
    <?php }?>
    <td colspan="2" align="center">
     <table width="300" height="144" border="0" cellpadding="0" cellspacing="0">
       <tr>
         <td width="211" rowspan="6"><span style="width:180; height:120;"><img src="<?php echo $myrow_2[picpath];?>" width="210" height="140" /></span></td>
         <td width="89"><span class="STYLE2">图片名称</span></td>
       </tr>
       <tr>
         <td><?php echo $myrow_2[picname];?></td>
       </tr>
       <tr>
         <td>所有人</td>
       </tr>
       <tr>
         <td><?php echo $myrow_2[upname];?></td>
       </tr>
       <tr>
         <td>上传时间</td>
       </tr>
       <tr>
         <td><?php echo $myrow_2[uptime];?></td>
       </tr>
     </table>  <?php  
     $number++;
    }
       
    ?>
    </td>
    </tr>
    <?php
    }
    ?>
    </table>//codego.net/tags/4/1/
    <table width="600" align="center" border="1" cellpadding="1" cellspacing="1" bordercolor="#FFFFFF" bgcolor="#8394BF">
      <tr>
        <td width="573" bgcolor="#FFFFFF"><table width="600" border="0" cellpadding="0" cellspacing="0">
                  <tr> 
                  <td width="102" height="22" align="center"><span class="STYLE2">总计图片:<?php echo $message_count;?> 张</span></td>
      <td width="100">当前是:<?php echo $page;?>页</td>
                    <td width="193" align="center"><span class="STYLE2"> 分页: 
     <?php
    $next=$link_type*10;               
    $n=$link_type-1;
    $m=$link_type+1;
    $prev_page=$page-10;
    if ($link_type==0){echo "<img src=\"images/02.jpg\" width=\"8\" height=\"9\" border=\"0\" title=\"首页\">";
    }else{ echo "<a href='index.php?vv=&vv=0&link_type=0&page=1&content'><img src=\"images/02.jpg\" width=\"8\" border=\"0\" height=\"9\" border=\"0\" title=\"首页\"></a>&nbsp;";
    $ccc=$vv-10;
    echo "<a href='index.php?vv=$vv&link_type=$m&page=$pnext&content'><img src=\"images/01.jpg\" width=\"8\" height=\"9\" border=\"0\" title=\"上十页\"></a>";
    }?>
                    <?php
              for ($j=1;$j<=$page_count;$j++) {
           $pnext=$next+$j;
           if ($mm==10){
           break;
       }
    if ($mm>$page_count){
    break;
    }
    if ($page_count-$vv<10){
       if ($mm>=$page_count-$vv){
    break;
    }
    }
    ?>
                    <?php
                            echo "<a href='index.php?vv=$vv&link_type=$link_type&page=$pnext&content'> $pnext </a>";
                           $mm=$mm+1;
               }
     ?>     
                    </span></td>
     <td width="97" align="center">
                       <span class="STYLE2">
                       <?php
    $vv=$vv+$mm;
           if ($page_count-$vv<=0){
                           echo "<img src=\"images/03.jpg\" width=\"8\" height=\"9\" border=\"0\" title=\"尾页\">";
       }else{
                           echo "<a href='index.php?vv=$vv&link_type=$m&page=$pnext&content'><img src=\"images/03.jpg\" width=\"8\" height=\"9\" border=\"0\" title=\"下十页\"></a>";
       }
                    if ($message_count==0){
         echo "没有记录!"; }
    ?>
                      </span> </td>
                  </tr>
    </table>
    </table>