⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 table.inc

📁 PHPLOB注释详细版 使用模板技术的好帮手 PHP最有用的东东了
💻 INC
📖 第 1 页 / 共 3 页
字号:
<?php/* * PHP Base Library * * Copyright (c) 1998-2000 NetUSE AG *                    Boris Erdmann, Kristian Koehntopp, *                    Jeffrey Galbraith * * $Id: table.inc,v 1.2 2000/07/12 18:22:35 kk Exp $ *  * History: 990617: Modularized entire table class. Modularity breaks larger *                  objects into smaller, autonomous objects in order to  *                  exercise OOP requirements of code reuse. This give  *                  programmers the ability to use the high-level code, or  *                  get down and dirty with the low-level code. *                  Everything I have changed should maintain backwards  *                  compatibility, except for show_table_heading_row_result(), *                  which was unpreventable in order to get the full  *                  magnitude of OOP. *          990618: Added table_cell_open(), table_cell_close(), *                  table_heading_cell_open() and table_heading_cell_close().  *                  Gives better modularity to class.(JSG) *          990619: Added $add_extra. If set, calls extra cell functions: *                  table_heading_row_add_extra and table_row_add_extra. *                  Override these functions in a derived class to add  *                  additional cells to a row of output data. *          990620: Added column name remapping. This allows the column names *                  of a database to be remapped into something more useful, *                  or, perhaps, another language. Array variable "map_cols" *                  added. (JSG) */   #==========================================================================  # Table (class)  #--------------------------------------------------------------------------  # Creates an HTML table based on either a PHP array or a  # database result.  #==========================================================================  class Table{  var $classname = "Table";              ## Persistence Support  var $check;                            ## if set, create checkboxes named                                          ## to the result of $check[$key]  var $filter = "[A-Za-z][A-Za-z0-9_]*"; ## Regexp: Field names to show  var $fields;                           ## Array of field names to show  var $heading;                          ## if set, create <th> section  var $add_extra;                        ## Call extra cell functions  var $map_cols;                         ## remap database columns to new names  #==========================================================================  ## Public functions  #==========================================================================  #==========================================================================  ## Page functions  #==========================================================================  #==========================================================================  # Function : start  #--------------------------------------------------------------------------  # Purpose  : Starts the display of a two-dimensional array in an HTML table  #            format.  # Arguments: $ary   - The 2D array to display.  #            $class - [optional] Used for CSS control.  # Returns  : The number of rows displayed.  # Comments : See function: show  # History  :  #==========================================================================  function start($ary, $class="")   {    return ($this->show($ary, $class));  }  #==========================================================================  # Function : start_result  #--------------------------------------------------------------------------  # Purpose  : Starts the display of a database query result in an HTML table  #            format.  # Arguments: $db    - The database result.  #            $class - [optional] Used for CSS control.  # Returns  : The number of rows displayed.  # Comments : See function: show_result  # History  :  #==========================================================================  function start_result($db, $class="")   {    return ($this->show_result($db, $class));  }  #==========================================================================  # Function : show  #--------------------------------------------------------------------------  # Purpose  : Starts the display of a two-dimensional array in an HTML table  #            format.  # Arguments: $ary   - The 2D array to diaplay.  #            $class - [optional] Used for CSS control.  # Returns  : The number of rows displayed.  # Comments :  # History  : 990616 - removed redundant code.(JSG)  #==========================================================================  function show($ary, $class="")   {    global $debug;        if (!$this->verify_2d_array($ary))      return 0;    $rows = 0;    $this->table_open($class);    if ($this->show_table_heading_row($ary, $class))      $rows = $this->show_table_rows($ary, $class);    $this->table_close($class);        return $rows;  }    #==========================================================================  # Function : show_result  #--------------------------------------------------------------------------  # Purpose  : Starts the display of a database query result in an HTML table  #            format.  # Arguments: $db    - The database result.  #            $class - [optional] Used for CSS control.  # Returns  : The number of rows displayed.  # Comments :  # History  :  #==========================================================================  function show_result($db, $class="")   {    if (!$this->verify_db($db))      return 0;    $rows = 0;    $this->table_open($class);	if ($this->show_table_heading_row_result($db, $class))      $rows = $this->show_table_rows_result($db, $class);      $this->table_close($class);        return $rows;  }  #==========================================================================  # Function : show_page  #--------------------------------------------------------------------------  # Purpose  : Starts the display of a two-dimensional array in an HTML table  #            format. Only the rows $start to $start+$num are displayed.  # Arguments: $ary   - The 2D array to diaplay.  #            $start - The starting row to display.  #            $num   - The number of rows to display.  #            $class - [optional] Used for CSS control.  # Returns  : The number of rows displayed.  # Comments :  # History  :  #==========================================================================  function show_page($ary, $start, $num, $class ="")   {    global $debug;        if (!$this->verify_2d_array($ary))      return 0;    $rows = 0;        $this->table_open($class);	if ($this->show_table_heading_row($ary, $class))      $rows = $this->show_table_page_rows($ary, $start, $num, $class="");    $this->table_close($class);        return $rows;  }  #==========================================================================  # Function : show_result_page  #--------------------------------------------------------------------------  # Purpose  : Starts the display of a database object in an HTML table  #            format. Only the rows $start to $start+$num are displayed.  # Arguments: $db    - The database result.  #            $start - The starting row to display.  #            $num   - The number of rows to display.  #            $class - [optional] Used for CSS control.  # Returns  : The number of rows displayed.  # Comments :  # History  :  #==========================================================================  function show_result_page($db, $start, $num, $class="")   {    global $debug;        if (!$this->verify_db($db))      return 0;    $rows = 0;    $this->table_open($class);    if ($this->show_table_heading_row_result($db, $class))		$rows = $this->show_table_page_rows_result($db, $start, $num, $class);    $this->table_close($class);        return $rows;  }  #==========================================================================  ## Row functions  #==========================================================================  #==========================================================================  # Function : show_table_heading_row  #--------------------------------------------------------------------------  # Purpose  : Uses the passed array to create an HTML header row.  # Arguments: $ary   - The array to use.  #            $class - [optional] Used for CSS control.  # Returns  : 1 on success, 0 on error.  # Comments :  # History  :  #==========================================================================  function show_table_heading_row($ary, $class="")  {    if (!$this->verify_2d_array($ary))      return 0;          if (isset($this->heading) && $this->heading)    {      reset($ary);      list($key, $val) = each($ary);      $this->table_heading_row($val, $class);    }    return 1;  }    #==========================================================================  # Function : show_table_heading_row_result  #--------------------------------------------------------------------------  # Purpose  : Uses the passed database object to create an HTML header row.  # Arguments: $db    - The database object  #            $class - [optional] Used for CSS control.  # Returns  : 1 on success, 0 on error.  # Comments :  # History  :  #==========================================================================  function show_table_heading_row_result($db, $class="")  {    if (!$this->verify_db($db))      return 0;    if ($this->heading)    {// (Jeff) ------------------------------      //      if ($db->num_rows() > 0 && $db->next_record())// rows are confirmed in $this->verify_db(), so no need to reverify// -------------------------------------      if ($db->next_record())      {        $this->table_heading_row($db->Record, $class);        $db->seek($db->Row-1);        return 1;      }      else      {// (Jeff) ------------------------------      // Shouldn't do this! Breaks modularity!// Call: table_close() instead from //       calling function. Comments to //       be removed in next release.// -------------------------------------//        $this->table_close($class);// -------------------------------------        return 0;      }    }    return 1;  }    #==========================================================================  # Function : table_heading_row  #--------------------------------------------------------------------------  # Purpose  : Outputs HTML code to create a table heading row.  # Arguments: $data  - The array of data that represents cells within a row.  #            $class - [optional] Used for CSS control.  # Returns  :  # Comments :  # History  : 990618 - Fixed return on select_colnames (JSG).  #==========================================================================  function table_heading_row($data, $class="")   {    if (!is_array($data))      return;    $d = $this->select_colnames($data);    $this->table_row_open($row, $d, $class);    $this->set_checkbox_heading($class);    $this->show_table_heading_cells($data, $class);    # call virtual function    if ($this->add_extra)      $this->table_heading_row_add_extra($data, $class);    $this->table_row_close(0, $class);  }  #==========================================================================  # Function : show_table_rows  #--------------------------------------------------------------------------  # Purpose  : Walks the passed array displaying each row of data as an HTML  #            table row.  # Arguments: $ary   - The array of data to display.  #            $class - [optional] Used for CSS control.  # Returns  :  # Comments :  # History  :  #==========================================================================  function show_table_rows($ary, $class="")  {    global $debug;        if ($debug)      printf("<p>show_table_rows()<br>\n");    if (!$this->verify_2d_array($ary))      return 0;      

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -