ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:connection:getmedian

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
v5:reference:connection:getmedian [2016/01/17 01:03] – ↷ Page moved from v5:reference:conection:getmedian to v5:reference:connection:getmedian mnewnhamv5:reference:connection:getmedian [2025/10/06 16:38] (current) mnewnham
Line 4: Line 4:
 == Syntax == == Syntax ==
    mixed getMedian {    mixed getMedian {
-         mixed string $table +     string $table 
-         mixed string $column +     string $column 
-         optional mixed string $where+     optional string $where
   }   }
 </WRAP> </WRAP>
  
 +The method getMedian() does not return a true [[https://en.wikipedia.org/wiki/Median|arithmetic median]] but simply returns the value of a specific column in a specified table closest to the middle of a record set, as specified by WHERE criteria.
  
-Returns the median value of $column for $table, or false if an error occurs+If the number of records in the recordset is an even number, it returns the lower of the 2 closest records
  
-The $where clause is optional, but if used, the WHERE statement must include the requested column  as in "WHERE name > 'A'". If an error occurs, false is returned.+Because the method does not perform an arithmetic operation on the returned data, it can be used on character fields as well as numeric. 
 + 
 + 
 + 
 +The $where clause is optional, but if used, the WHERE statement must begin with the keyword //**WHERE**//, as in "WHERE name > 'A'" 
 + 
 +If an error occurs or a median row cannot be determined (for example the table is empty), false is returned.
 ------------------------------ ------------------------------
 ==== Usage ==== ==== Usage ====
Line 22: Line 29:
 $table = 'zip_codes'; $table = 'zip_codes';
 $column = 'population'; $column = 'population';
 +$where  = 'WHERE zip_code IN (80401,80402,80403)';
 +
 +$medianPopulation = $db->getMedian($table,$column,$where);
  
-$medianPopulation = $db->getMedian($table,$column); 
 </code> </code>
  
v5/reference/connection/getmedian.txt · Last modified: by mnewnham