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

Next revision
Previous revision
reference:getmedian [2015/07/18 04:06] – created mnewnhamv5:reference:connection:getmedian [2025/10/06 16:38] (current) mnewnham
Line 1: Line 1:
-====== GetMedian ======+====== getMedian ======
 ~~NOTOC~~ ~~NOTOC~~
 <WRAP right box> <WRAP right box>
 == 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 optionalbut 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 datait 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 ====
 <code php> <code php>
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.1437185187.txt.gz · Last modified: (external edit)