[REVIEW] database->loadResultArray

Last reviewed: Not reviewed
phpDocumentor

database->loadResultArray

Returns an array containing a single field from all the rows returned by the database query.

Syntax

array loadResultArray ( [ integer $num_in_array ] )

$num_in_array
is the numeric offset of the field in the database row.  This field is optional and if omitted will return the first field in each row (that is, field 0).

Returns null if the last database query failed.

Examples

Example: This function prints an array of titles from the Joomla categories table.

function getCategoryTitles() {
  global $database;
 
  $sql = 'SELECT id, title, description FROM #__categories';
  $database->setQuery( $sql );
  $titles = $database->loadResultArray( 1 );
  print_r( $titles );
 
}
 
getCategoryTitles();

might produce:

Array
(
    [0] => Latest
    [1] => Joomla
    [2] => Newsflash
    [3] => Contacts
)
 

Please report any errors on this page to the Developer Documentation Forum.

Last Updated ( Monday, 25 December 2006 )