分页显示记录集错误,怎么回事?
我有两个文件index.php
源码为:
程序代码:
<?php require_once("conn.php"); function show_result($sql,$conn) { $result=mysql_query($sql,$conn); $col_num=mysql_num_fields($result); $row_num=mysql_num_rows($result); if($row_num==0) die("未找到任何记录!\n"); printf("<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\" >\n"); printf("<caption>用户个人信息(每页显示%d记录)</caption>\n",$row_num); printf("<tr bgcolor=\"#CCCCCC\">\n"); for ($i=0;$i<$col_num;$i++) { $meta=mysql_fetch_field($result); printf("<th>%s</th>\n",$meta->name); } printf("</tr>\n"); for($i=0;$i<$row_num;$i++) { $row=mysql_fetch_array($result); printf("<tr>\n"); for($j=0;$j<$col_num;$j++) printf("<th>%s</th>\n",$row[$j]); printf("</tr>\n"); } printf("</table>\n"); mysql_free_result($result); } function paging($cur_page,$sql,$conn,$page_size) { $row_count=mysql_num_rows(mysql_query($sql,$conn)); //获取总的记录数 $page_count=ceil($row_count/$page_size); $page_index=isset($_GET["page"])?$_GET["page"]:1; if(!is_numeric($page_index) or($page_indx<1)) $page_index=1; if($page_index<1) $page_index=1; if($page_index>$page_count) $page_index=$page_count; $start_row=($page_index-1)*$page_size; $sql_limit=sprintf("%s LIMIT %d,%d",$sql,$start_row,$page_size); show_result($sql_limit,$conn); printf("<form name=\"form1\" action=\"\" method=\"get\">\n"); printf("当前位置:%d/%d 共 %d 条记录<br />\n",$page_index,$page_count,$row_count); for($i=1;$i<=$page_count;$i++) { if($i!=$page_index) printf("<a href=\"%s?page=%d\">[%d]</a> \n",$cur_page,$i,$i); else printf("<b><font color=\"red\">%d</font></b> \n",$i); } } printf("</form>\n"); ?>另一个文件
indexbat.php
源码为:
程序代码:
<?php require_once("index.php"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www. xmlns="http://www. http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>分页显示记录集</title> </head> <body> <?php $page_size=2; $sql="select m_user as 姓名,m_pass as 密码,m_mail as 邮箱,m_ip as IP地址,m_time as 登录时间 from info"; paging($PHP_SELF,$sql,$conn,$page_size); ?> </body> </html>
运行indexbat.php文件就会显示如图
当我按下2的时候,居然没有反应。该当如何啊,请赐教。(3,4一样)
麻烦各位了