Documentation

get_all


get_all

Return the selected rows

$user_list = db::get_all("SELECT * FROM user WHERE name=?", array("Luke")  );

 

get_all( field, query, key )
This option returns the rows indexed by the selected key

// returns array( 33 =>array('id'=>33, 'name'=>'Leila', 'lastname'=>'red'), 156 =>array('id'=>156, 'name'=>'Leila', 'lastname'=>'blue'), 981 =>array('id'=>981, 'name'=>'Leila', 'lastname'=>'green')
$content_type_list = db::get_all("SELECT * FROM user WHERE name=?", array("Leila"), "user_id" );

 


get_all( query, key, value )
This option gets the result as associative array with the selected key and the value. In this case it is convenient to write the query with only key and value field selected

// returns array( 'AL'=>'afghanistan', 'AB'=>'Albania'  ...  'Zimbabwe'=>'ZW' );
$country_list = db::get_all("SELECT country_id,country_name FROM country", null,  "country_id", "country_name" );

 

Assign results to template

get_all is designed to work in combination with the View class to assign the list to the template, very useful for every kind of list, such as user list, news list, etc.

$view = new View;
$view->assign( "country_list", $country_list );


and this is how the template with RainTPL looks:

{loop="country_list"}
    {$key} = {$value}
{else}
   list empty
{/loop}

 

Profiler output