Answer the question
In order to leave comments, you need to log in
MSSQL in Yii2. How to sort data correctly?
Not strong in OOP. 10 years ago I coded structurally in PHP :)
I started studying OOP and Yii2
#MSSQL2008 via freeTDS7.3 @linux
<?php
namespace frontend\models;
use yii\db\ActiveRecord;
class Plist extends ActiveRecord
{
public static function getDb()
{
return \Yii::$app->db2;
}
public static function tableName() {
return 'dbo.pList';
}
}
?>
$pList = Plist::find()
->select('ID, Name, FirstName, MidName, WorkPhone, HomePhone, BirthDate')
->filterWhere(['like', 'Name', $searchQuery])
//->orderBy('Name')
//->all()
;
Хочу дальше работать с результатом так:
<?php foreach ($pList as $t) { ?>
<li><?=$t->Name." ".$t->FirstName." ".$t->MidName?></li>
<?php } ?>
SQLSTATE[HY000]: General error: 20018 Column "dbo.pList.Name" is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause. [20018] (severity 16) [(null)]
The SQL being executed was: SELECT COUNT(*) FROM [dbo].[pList] ORDER BY [Name]
/*$pagination = new Pagination([
'defaultPageSize' => 20,
'totalCount' => $pList->count()
]);*/
//$pList = $pList->offset($pagination->offset)->limit($pagination->limit)->all();
$pList = $pList->orderBy($sort->orders)->offset($pagination->offset)->limit($pagination->limit)->all();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question