home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / rsfilter.inc.php < prev    next >
Encoding:
PHP Script  |  2004-03-20  |  1.4 KB  |  54 lines

  1. <?php
  2. /** 
  3.  * @version V4.21 20 Mar 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights reserved.
  4.  * Released under both BSD license and Lesser GPL library license. 
  5.  * Whenever there is any discrepancy between the two licenses, 
  6.  * the BSD license will take precedence. 
  7.  *
  8.  * Set tabs to 4 for best viewing.
  9.  * 
  10.  * Latest version is available at http://php.weblogs.com
  11.  *
  12.  * Requires PHP4.01pl2 or later because it uses include_once
  13. */
  14.  
  15. /*
  16.     Filter all fields and all rows in a recordset and returns the 
  17.     processed recordset. We scroll to the beginning of the new recordset
  18.     after processing.
  19.     
  20.     We pass a recordset and function name to RSFilter($rs,'rowfunc');
  21.     and the function will be called multiple times, once
  22.     for each row in the recordset. The function will be passed
  23.     an array containing one row repeatedly.
  24.     
  25.     Example: 
  26.      
  27.     // ucwords() every element in the recordset
  28.     function do_ucwords(&$arr,$rs)
  29.     {
  30.         foreach($arr as $k => $v) {
  31.             $arr[$k] = ucwords($v);
  32.         }
  33.     }
  34.     $rs = RSFilter($rs,'do_ucwords');
  35.  */
  36. function &RSFilter($rs,$fn)
  37. {
  38.     if ($rs->databaseType != 'array') {
  39.         if (!$rs->connection) return false;
  40.         
  41.         $rs = &$rs->connection->_rs2rs($rs);
  42.     }
  43.     $rows = $rs->RecordCount();
  44.     for ($i=0; $i < $rows; $i++) {
  45.         $fn($rs->_array[$i],$rs);
  46.     }
  47.     if (!$rs->EOF) {
  48.         $rs->_currentRow = 0;
  49.         $rs->fields = $rs->_array[0];
  50.     }
  51.     
  52.     return $rs;
  53. }
  54. ?>