里面都有注释的,自己研究一下吧!不懂也可以找我,我尽量帮忙了!
<?
/// <Copyleft>
///   <Program name="Author">Whiten Shen</Program>
///   <Program name="Version">1980.11.01</Program>
///   <Program name="Email">[email protected]</Program>
///   <Program name="OICQ">6671258</Program>
/// </Copyleft>
?>
<?
class MYSQLService {    var $Database;
    var $ConnectionID;
    var $QueryID;
    var $DataRows;
    var $a_Rows;
    var $Result;    /// <summary>
    /// Default constructor, You can set database via setting parameter
    /// </summary>
    function MYSQLService($strDatabase = "Shop"){
             $this->Database = $strDatabase;
    }    /// <summary>
    /// Start MYSQL Service & Select Database, then Return Connection ID
    /// <return> Connection ID </return>
    /// </summary>
    function StartService(){
             if(!$this->ConnectionID){
                 $this->ConnectionID = mysql_pconnect("localhost", "root", "admin") or MYSQL_ErrorMsg("Fail to connect to MYSQL SERVER!");
             }
             if(!$this->Database){
                 $this->Database = "Shop";
             }
             @mysql_select_db($this->Database, $this->ConnectionID) or MYSQL_ErrorMsg("fail to select database!");             return $this->ConnectionID;
    }    /// <summary>
    /// Change object Database
    /// </summary>
    function ChangeDatabase($strDatabase){
             if($strDatabase){
                $this->Database = $strDatabase;
              }
    }    /// <summary>
    /// SQL query, get Query ID and Data DataRows, then Return Query ID
    /// <return> Query ID </return>
    /// </summary>
    function Query($QueryString){
             $this->QueryID = @mysql_query($QueryString, $this->StartService()) or MYSQL_ErrorMsg ("fail to QUERY!");
             $this->DataRows = @mysql_num_rows($this->QueryID);
             $this->a_Rows = @mysql_affected_rows($this->QueryID);             return $this->QueryID;
    }    /// <summary>
    /// A useful function for querying only a single DataRow. It will return fetch Result.
    /// </summary>
    function QueryRow($QueryString){
             $this->QueryID = @mysql_query($QueryString, $this->StartService()) or MYSQL_ErrorMsg("Fail to QUERY!");
             $this->Result = @mysql_fetch_array($this->QueryID) or MYSQL_ErrorMsg("Fail to Fetch!");
             $this->DataRows = @mysql_num_rows($this->QueryID);
             $this->a_Rows = @mysql_affected_rows($this->QueryID);
    }    /// <summary>
    /// It will return an array variable Result.
    /// This function is suitable to getting Multiple Result.
    /// <return> Result </return>
    /// </summary>
    function Fetch($FetchString){
             $this->QueryID = $this->Query($FetchString);
             if(isset($this->Result)){
                unset($this->Result);
             }
             while($DataRow = mysql_fetch_array($this->QueryID)){
                   $this->Result[] = $DataRow;
             }
    }    /// <summary>
    /// Insert method
    /// </summary>
    function Insert($InsertString){
             $this->QueryID = @mysql_Query($InsertString, $this->StartService()) or MYSQL_ErrorMsg("Fail to perform INSERT!");
             $this->a_Rows = @mysql_affected_rows($this->QueryID);
    }    /// <summary>
    /// update method
    /// </summary>
    function Update($UpdateString){
             $this->QueryID = @mysql_Query($UpdateString, $this->StartService()) or MYSQL_ErrorMsg("Fail to perform UPDATE!");
             $this->a_Rows = @mysql_affected_rows($this->QueryID);
    }    /// <summary>
    /// Remove method
    /// </summary>
    function Remove($RemoveString){
             $this->QueryID = @mysql_Query($RemoveString, $this->StartService()) or MYSQL_ErrorMsg("Fail to perform REMOVE!");
             $this->a_Rows = @mysql_affected_rows($this->QueryID);
    }    /// <summary>
    /// Free Query Result if necessary.
    /// </summary>
    function FreeResult(){
        mysql_free_result($this->QueryID);
    }    /// <summary>
    /// Close MYSQL connetion if necessary.
    /// </summary>
    function CloseService(){
             mysql_close();
    }
}/// <summary>
/// An inherit class of MYSQLService.
/// It is specially designed for Paging.
/// </summary>
class PageView extends MYSQLService{
      var $Table;
      var $PageSize;
      var $Offset;
      var $Total;
      var $TotalPage;
      var $CurrentPage;
      var $Condition;
      var $PageQuery;      /// <summary>
      /// Default constructor.Initialize variable.
      /// You shall give, at least, 2 variable - object table & page
      /// PageSize for Paging is 10.
      /// </summary>
      function PageView($strTable, $iPage, $iPageSize = 10){
               $this->Table = $strTable;
               $this->PageSize = $iPageSize;
               $this->CurrentPage = $iPage;
               $this->Offset = $iPageSize * ($iPage - 1);
               $this->Condition = "";
      }      /// <summary>
      /// Set query condition.
      /// </summary>
      function SetCondition($s){
               $this->Condition = $s;
      }      /// <summary>
      /// Set PageQuery for Paging.
      /// </summary>
      function SetPageQuery($key, $value){
               $tmp[Key] = $key;
               $tmp[Value] = $value;
               $this->PageQuery[] = $tmp;
      }      /// <summary>
      /// Get Data List. Return Total DataRow & Data Result.
      /// </summary>
      function GetList(){
               $SQLString = "SELECT Count(*) AS Total FROM ".$this->Table." ".$this->Condition;
               $this->QueryRow($SQLString);
               $this->Total = $this->Result[Total];               if($this->Total > 0){
                  $SQLString = "SELECT *  FROM ".$this->Table." ".$this->Condition." LIMIT ".$this->Offset.",".$this->PageSize;
                  $this->Fetch($SQLString);
               }
               else{
                    echo "<br><font color=#FF9900 size=4>Sorry, we can not find what you want after searching our store directory.</font><br>";
                    echo "<br><a href=# onclick=history.back()>返回前页</a>";
                    exit();
               }
      }      /// <summary>
      /// Show Current page & Total page.
      /// </summary>
      function PageInfo(){
               $this->TotalPage = ceil($this->Total / $this->PageSize);
               if($this->Total == 0){
                  $this->CurrentPage = 0;
               }
               else{
                    $this->CurrentPage = $this->Offset/$this->PageSize + 1;
                    echo $this->CurrentPage."/".$this->TotalPage."pages";
               }
      }      /// <summary>
      /// Show link - First page, Next page, Previous page, Last page
      /// </summary>
      function PageLink(){
               $First = 1;
               $Last = $this->TotalPage;
               $Next = $this->CurrentPage + 1;
               $Previous = $this->CurrentPage -1;               $k=count($this->PageQuery);
               $strQuery="";
               for($i=0;$i<$k;$i++){
                   $strQuery.="&".$this->PageQuery[$i][Key]."=".$this->PageQuery[$i][Value];
               }               if($Previous > 0){
                  echo "<A href=$PHP_SELF?Page=".$First.$strQuery.">First</A> ";
                  echo " <A href=$PHP_SELF?Page=".$Previous.$strQuery.">Previous</A> ";
               }
               if($Next <= $Last){
                  echo " <A href=$PHP_SELF?Page=".$Next.$strQuery.">Next</A> ";
                  echo " <A href=$PHP_SELF?Page=".$Last.$strQuery.">Last</A>";
               }
      }      function PageLinkOnPic(){
        global $CFG;
        $this->TotalPage=ceil($this->Total/$this->PageSize);
        $Next=$this->CurrentPage+1;        $k=count($this->PageQuery);
        $strQuery="";
        for($i=0;$i<$k;$i++){
            $strQuery.="&".$this->PageQuery[$i][Key]."=".$this->PageQuery[$i][Value];
        }        if($Next<=$this->TotalPage)
                  echo " <A href=$PHP_SELF?page=".$Next.$strQuery.">
                          <img src=\"".$CFG->ImgCommDir."/button-more-results.gif\" border=0 hspace=5 vspace=2 alt=\"MORE PRODUCTS\">
                         </A> ";
    }
}/// <summary>
/// Show Error Message
/// </summary>
function MYSQL_ErrorMsg ($msg)
{
    $Text  = "<font color=\"#ff0000\"><p><b>Error: $msg :";
    $Text .= mysql_error();
    $Text .= "</b></font>";
    $ErrorMsg=$Text;    echo "$ErrorMsg";
    die("Unable to continue!");
}
?>

解决方案 »

  1.   

    好像用到了xml?我就不懂了。。
      

  2.   

    这个简单
    <?php
    //*********************************************
    //  名称: 数据操作程序 v 1.1
    //  脚本: php 4.0.6
    // 数据库: mysql 3.23.41
    //  制作: [email protected]
    // 完成: 2001-9-23 22:55
    // 备注: 此程序中的翻页算法通用于所有数据库
    //   更换数据库只需更换php数据库函数
    // 需要自己定制的变量注释后面有" * "
    //  Copyright By 开花石头 ◎ 2001
    //*********************************************
    mysql_connect('localhost','root','');
    mysql_select_db('cngift');//所操作的表名*
    $table_name = "cngift_test";//处理删除程序
    if(isset($cngift[0])){
    for($i = 0;$i<sizeof($cngift);$i++){ $Del_Sql = "Delete from ".$table_name." where ".$sign_value."='$cngift[$i]'";
    mysql_query($Del_Sql);

    }
     echo "<script>alert('共删除了".$i."条数据!')</script>";
    }
    //显示列表数目*
    $NUM_OF_1_PAGE = 1;
    $num_of_pages = 0 ;
    $current_page = 0;
    //定义列表的表头(注:$table_title和table_value的顺序一定不能错)*
    $table_title = array("编号","品名","单价");//定义列表显示内容的数据库字段名(注:select的值不一定都要显示)*
    $table_value = array("id","name","money");//定义显示列表的sql语句的返回值*
    //列表显示的值一定要写在返回值的最前面*
    $return = "id,name,money";//当需要倒叙显示数据时请填写倒叙的数据库字段*
    $flashback = "id";//定义sql语句中where后面的条件语句,字串中不需要写where*
    //当需要id='$id'时,直接写$where = "id='$id'"*
    $where = "";//定义select中的条件变量作为计算翻页时的传递变量*
    //如果$where = "id='$id' and name='$name'"*
    //则$impress = "id='$id'&&name='$name'";*
    $impress = "";//定义进行数据操作中的参数值,一定是sql中取到的有唯一值的字段*
    $sign_value = "id";$sql = "select ".$return." from ".$table_name;//处理一般列表
    if($where != ""){

    $sql = "select ".$return." from ".$table_name." where ".$where;
    }//处理搜索
    if($search_select != ""&&$search_value != ""){

    $sql = "select ".$return." from ".$table_name." where ".$search_select." like '%".$search_value."%'";

    if($where != ""){

    $sql = "select ".$return." from ".$table_name." where ".$where." and ".$search_select." like '%".$search_value."%'";
    }}//处理sql语句倒叙
    if($flashback != ""){
    $sql.= " order by ".$flashback." desc";
    }
    $query = mysql_query($sql);

    //翻页处理程序
    $num_of_rows=mysql_num_rows($query);//设置起始位置
    if(!$start_num){$start_num=0;}
     ($num_of_rows - $start_num)>$NUM_OF_1_PAGE? $num_of_rows_on_current_page =$NUM_OF_1_PAGE:$num_of_rows_on_current_page = $num_of_rows - $start_num;
    $next_page = $start_num + $NUM_OF_1_PAGE;
    $previous_page = $start_num - $NUM_OF_1_PAGE;if($next_page>=$num_of_rows){$next_page=$start_num;}
    if($previous_page<=0) {$previous_page=0;}$last_page = $num_of_rows%$NUM_OF_1_PAGE;
    if($last_page==0){$last_page = $num_of_rows - $NUM_OF_1_PAGE;}
    else{$last_page = $num_of_rows - $last_page;}
            
    //所有的页
    $num_of_pages = (int)($num_of_rows/$NUM_OF_1_PAGE)  ;
    if($num_of_rows%$NUM_OF_1_PAGE !=0 ) $num_of_pages++;

    //当前页
    $current_page = (int)($start_num / $NUM_OF_1_PAGE) +1 ;
    if($start_num % $NUM_OF_1_PAGE !=0) $current_page ++;$table_title_num = sizeof($table_title);
    $table_value_num = sizeof($table_value);
    ?><html>
    <head>
    <title>数据操作程序 v 1.1</title>
    <meta content="text/html; charset=gb2312">
    <script language="JavaScript">
    function SelectAll(){
    var items = document.cngift.elements[0];
    for(var i=0;i<document.cngift.elements.length;i++){
    if(document.cngift.elements[i].type != "checkbox"){
    continue;}
    items = document.cngift.elements[i];
    if(items.name = 'cngift[]')
    items.checked = true;
    }
    }
    function doSelect(frm)
    {
    if(frm.c.checked == "")
    {
    frm.a.readOnly = true;
    }else{frm.a.readOnly = false;}
    }
    </Script>
    </head><body bgcolor="#FFFFFF">
    <form method="post" action=<?=$PHP_SELF?> name="cngift">
      <table width="350" border="1" bordercolorlight="#000000" bordercolordark="#FFFFFF" cellpadding="0" cellspacing="0">
        <tr>
        <?php
         //表头处理
         for($i=0;$i<$table_title_num;$i++){
        ?>
          <td height="20"> 
            <div align="center"><font size="2"><?=$table_title[$i]?></font></div>
          </td>
        <?}?>
          <td height="20"> 
            <div align="center"><font size="2">维护操作</font></div>
          </td>
        <tr>
        <?php   
         @mysql_data_seek($query,$start_num);
            for($j=0;$j<$num_of_rows_on_current_page;$j++)
            {
         //内容列表
         $rs = mysql_fetch_array($query);
         for($i=0;$i<$table_value_num;$i++){
        ?> 
          <td height="20"> 
            <div align="center"><font size="2"><?=$rs[$i]?></font></div>
          </td>
          <?php
           }//for end
      ?>
          <td> 
            <div align="center"> <font size="2"> 
              <input type="checkbox" name="cngift[]" value=<?=$rs[$sign_value]?>>
            </font></div>
          </td>
        </tr>
          <?php
    }//for end
          ?>    <tr> 
          <td colspan="4"> 
            <div align="center"> 
             <input type="hidden" name="start_num" value=<?=$start_num?>>
             <input type="hidden" name="sign_value" value=<?=$sign_value?>>
             <input type="hidden" name="search_value" value=<?=$search_value?>>
             <input type="hidden" name="search_select" value=<?=$search_select?>>
                <input type="submit" name="Submit" value="删除" onClick="return confirm('你真的要删除所选信息?!');">
       <input type=button value=全选 onClick='SelectAll()'>
       <input type=reset value=全不选>
       <input type=button value=版权信息 onClick="return confirm('数据操作程序 v 1.1\n\nCopyright By 开花石头 ◎ 2001\n\nEmail:[email protected]');">
            </div>
          </td>
        </tr>
        <tr> 
          <td colspan="4"> 
            <div align="center"><font size="2">| 
    <?if($current_page != 1){echo "<a href=$PHP_SELF?start_num=0&&search_select=$search_select&&search_value=$search_value&&$impress>";}?>首页</a>&nbsp;
    <?if($current_page != 1){echo "<a href=$PHP_SELF?start_num=$previous_page&&search_select=$search_select&&search_value=$search_value&&$impress>";}?>上一页</a>&nbsp;
    <?if($current_page != $num_of_pages&&$num_of_pages != 0){echo "<a href=$PHP_SELF?start_num=$next_page&&search_select=$search_select&&search_value=$search_value&&$impress>";}?>下一页</a>&nbsp;
    <?if($current_page != $num_of_pages&&$num_of_pages != 0){echo "<a href=$PHP_SELF?start_num=$last_page&&search_select=$search_select&&search_value=$search_value&&$impress>";}?>尾页</a>|
            </font></div>
          </td>
        </tr>
      </table>
    </form>
    <form method="post" action="">
      <input type="text" name="search_value" size="15">
      <select name="search_select" >
        <option value="">选择检索类</option>
        <?php
         for($i=0;$i<$table_title_num;$i++){
         //显示检索条件
         echo"<option value=$table_value[$i]>$table_title[$i]</option>";
         }
        ?>
      </select>
      <input type="hidden" name="start_num" value="">
      <input type="submit" name="Submit" value="检索">
    </form>
    </html><!--
    本程序为1.1版本,其中修改了包括查询列表显示错误及其他的一些bug版权信息在转载的时候必须保留,但在使用中悉听尊便,包括个人与企业
    如果您发现了本程序功能与设计中的bug,请及时通知
    -->
      

  3.   

    用sql 的 limit 子句分页啊?自己保存页码和每页要显示的数量,通过url传递该参数即可。
      

  4.   

    limit 有些数据库不支持的