PX : code

Table Class by Jonathan Meyer
Download this code


<?php
/* Table class
 *
 * by Jonathan Meyer
 * September 2002
 *
 * Latest version available here:
 * http://px.sklar.com/code.html?id=903
 */

class Table
{
  var 
$records;
  
  function 
Table()
  {
    
$this->records = array();
  }
  
  function 
add_record$record )
  {    
    
array_push$this->records$record );
  }

  function 
count()
  {
    return 
count$this->records );
  }
  
  function 
row$record_number )
  {
    return 
$this->records[$record_number];
  }
  
  function 
column$field_name )
  {
    
$c = array();
    
    foreach( 
$this->records as $r )
    {
      
array_push$c$r[$field_name] );
    }
    
    return 
$c;
  }
  
  function 
cell$field_name$record_number )
  {
    if( ! 
$record_number )
    {
      
$record_number 0;
    }
    
    return 
$this->records[$record_number][$field_name];
  }
}
php?>

Comments or questions?
PX is running PHP 5.2.17
Thanks to Miranda Productions for hosting and bandwidth.
Use of any code from PX is at your own risk.