|
Method sortByField( $sName, $sBy = «asc», $sType = SORT_NUMERIC ) |
|
Written by Hidalgo Emmanuel
|
|
Description :
Allows to sort a collection on a field.
Parameters :
$sName, string : e of the field on which the sorting will be made $sBy (optional), string : Indicate the direction of the sorting, «asc», indicating an ascending sorting «desc», indicating a tri descendant By defect this parameter is equal to «asc» $sType (optional), constant : Inform the type of type to be carried out SORT_NUMERIC, indicating a kind of numerical field SORT_STRING, indicating a kind of field string
Value of return :
No parameter of return.
The following example posts a list of “users” sorted by name in a downward way :
<?php
//total instanciation include_once( 'phpsimpledb.class.php' ); Global $oBDD; $oBDD = new PHPSIMPLEDB(); // recover a collection of “users” $oUsers_col = $oBDD->getCollection( "users" ); $oUsers_col->load(); // Tri descendant at once “name” $oUsers_col->sortByField( "name", "desc", SORT_STRING ); //print a "users" foreach($oUsers_col->getObjects() as $oUser ){ print( "name : ".$oUser->getData_field( "name" )."<br/>" ); }
?>
|
|