メインコンテンツまでスキップ
Version: Fegg 5.x(開発版)

Model::group

Set Group Parameter

Description​

public self Model::group( string $group )

Adds GROUP BY. Several calls are joined with commas. The text is written into the SQL as it is: never put user input in it. With group(), count counts the groups.

Arguments​

NameData typeDefaultRemarks
$groupstringGroup column(s)

Example​

Controller
$model = new Model(false, array(
'table' => 'cms_news',
'id' => 'news_id',
'visible' => 'visible',
));

// Select category, count(*) AS n
// From "cms_news"
// Where ...
// Group By category
$records = $model->select('category, count(*) AS n')->group('category')->all();

// Number of categories that have news
$categories = $model->group('category')->count();