你想要什么版本的?我自己写了一套函数,可以完成上述功能,具体实现如下,先定义了数据库连接模块,这个模块用来解决数据库的连接问题,在此模块的基础上,编写了数据库操纵函数,函数包括查询插入修改删除四个基本数据库操作函数,前面这两部分都是根据不同的数据库编写的,目前已经写好mysql的,oracle的,并且查询插入修改删除四个基本数据库操作函数,各个数据库版本所需参数完全一样,对上一层的接口一至(其实这个不能算是接口),就是说实际编写应用的时候,所有的数据库操作都是透明的,你只需要给出这些参数,(利用函数来实现比对象好,函数可以一条语句就完成一个相应查询,而对象还要用new建立对象等等操作,复杂),在四个数据库操作函数的基础之上,再编写分页模块,就可以了(分页我也是使用函数做的,PHP的对象操作太笨拙)。以下是我编写的MYSQL版的上述函数,是最完整的一个版本,其中还有很多地方需要完善,再下面是一个示例程序,其中都没有填写注释,缺憾吧,没有来得及写还。<?
// PHP database access for mysql version 1.0
// WRITTEN BY RUNMIN 2001-9-12
// COPYRIGHT 2001 RUNMIN ALL RIGHTS RESERVEDfunction delete_rows($name,$cond)
{
$conn = db_conn();
$query = "delete from ".$name." ".$cond;
mysql_close();
return mysql_query($query,$conn);
}function insert_row($name,$value)
{
$conn = db_conn();
$val = "'";
for ($i=0;$i<count($value)-1;$i++)
{
$val .= $value[$i]."','";
}
$val .= $value[$i]."'";
$query = "insert into ".$name." values(".$val.")";
mysql_close();
return mysql_query($query,$conn);
}function update_column($field,$value,$name,$cond)
{
$conn = db_conn();
$query = "update ".$name." set ".$field." = '".$value."' ".$cond;
mysql_close();
return mysql_query($query,$conn);
}function select_column($field,$name,$cond)
{
$conn = db_conn();
$query = "select ".$field." from ".$name." ".$cond;
if (!strpos($field,"distinct")) $field = ereg_replace("distinct ","",$field);
$res = mysql_query($query,$conn);
if (mysql_num_rows($res)==0) return false;
for ($i=0;$i<mysql_num_rows($res);$i++)
{
$result[$i] = mysql_result($res,$i,$field);
}
mysql_close();
return $result;
}//**********************************************************************function page($page_num,$max_rec,$result)
{
        for ($i=($page_num-1)*$max_rec;$i<$page_num*$max_rec;$i++)
        {
                if ($i>=count($result)) break;
                $page_rec[$i-($page_num-1)*$max_rec] = $result[$i];
        }
        return $page_rec;
}function get_page_infor($page_num,$max_rec,$result)
{
        $page_infor = "<center>共<font color=red> ".count($result)." </font>条记录,每页<font color=red> ".$max_rec." </font>条记录,当前是第 <font color=red>$page_num</font> 页</center>";
        return $page_infor;
}function get_jump_interface($page_num,$max_rec,$result,$url)
{
if (count($result)%$max_rec == 0) $maxnum = count($result)/$max_rec;
else $maxnum = ((int)(count($result)/$max_rec))+1;
        echo "<center><form name='pag' method='post' action =$url>";
        if ($page_num!=1)
        {
                echo "<a href=",$url,"pagenum=1>第一页</a>&nbsp;";
                echo "<a href=",$url,"pagenum=",$page_num-1,">前一页</a>&nbsp;";
        }
        else echo "第一页&nbsp;前一页&nbsp";
        ?>
        <select name=pagenum onchange="pag.submit()">
<?
        for ($i=1;$i<=$maxnum;$i++)
        {
                echo "<option value='$i'";
                if ($i==$page_num) echo "selected";
                echo ">$i</option>";
        }
?>
        </select>
        <?
        if ($page_num!=$maxnum)
        {
                echo "&nbsp;<a href=",$url,"pagenum=",$page_num+1,">后一页</a>&nbsp;";
                echo "<a href=",$url,"pagenum=".$maxnum.">最后一页</a>";
        }
        else echo "后一页&nbsp;最后一页&nbsp";
        echo "</center></form>";
}
?>

解决方案 »

  1.   

    示例程序<link rel="stylesheet" href="/public/style.css" type="text/css">
    <?
    include "../../public/db.inc";
    include "../../public/db_acce.php"; $name = "ht_02circle_infor";
    $cond = "order by circle_id";
    $max = 15; $result = select_column("circle_name",$name,$cond);
    $page_result = page($pagenum,$max,$result); $circle_id = select_column("circle_id",$name,$cond);
    $page_circle_id = page($pagenum,$max,$circle_id); $corp_id = select_column("corp_id",$name,$cond);
    $page_corp_id = page($pagenum,$max,$corp_id);

    $circle_stat = select_column("circle_status",$name,$cond);
    $page_user_id = page($pagenum,$max,$circle_stat);

    echo "<table width=80% align=center bordercolor=#FECDCB border=1 cellspacing=1 cellpadding=1>";
    for ($i=0;$i<count($page_result);$i++) echo "<tr><td width=20% align=center>",$page_circle_id[$i],"</td><td width=30% align=center>",$page_corp_id[$i],"</td><td width=50% align=center>",$page_result[$i],"</td><td width=50% align=center>",$page_user_id[$i],"</td></tr>"; echo "<tr><td align=center colspan=7><br>";
    get_jump_interface($pagenum,$max,$result,"test.php?");
    echo "</td></tr>";
    echo "<tr><td align=center colspan=7>",get_page_infor($pagenum,$max,$result),"</td></tr></table>";
    ?>
      

  2.   

    示例程序中db.inc是数据库连接模块,db_acce.php就是上面所写的函数,每次进行分页的时候,只要修改test.php(示例程序)中select_column()然后调用分页函数将其分页,调用分页信息函数,分页跳转函数,就可以了,test.php可以做为数据库操纵模块上层的应用逻辑来编写,在通过特定的编程结构(在HTML页面中用include包含应用逻辑模块),就可以实现PHP代码与HTML的分离,上述思想已经编写成实际应用,效果还不错,^_^
      

  3.   

    之所以要这么编写无非是希望自己写出来的系统便于移植(不同数据库之间移植),并且将程序与HTML分离开来,会给程序的修改带来很大方便,在我写的应用中已经明显的表现出了修改的方便。^_^