E
E
EVOSandru62015-01-09 07:59:06
MySQL
EVOSandru6, 2015-01-09 07:59:06

Why doesn't $criteria->order work in Yii?

Such a trouble, you need to sort the list by field in the table ` ORDER `
$criteria = new CDbCriteria();
1) I tried this: - swears at the word ORDER (system), I put it in `quotes` 2) I try - the records still go through the field CODE(AI , PRIMARY KEY) 3) - the same as 2) When I tried the item 1) received such a thing Added quotes and inserted into phpmyadmin naked: In this case, I got the records in the order I needed. But I don't understand where the `t` came from and why the records are displayed. But the most important thing is how to make this criterion work?
$criteria->order = 'ORDER ASC';
$criteria->order = '`ORDER` ASC'
$criteria->order = '`ORDER`'
SELECT * FROM `mc_slider` `t` ORDER BY ORDER
SELECT * FROM `mc_slider` `t` ORDER BY `ORDER`

Answer the question

In order to leave comments, you need to log in

2 answer(s)
_
_ _, 2015-01-09
@AMar4enko

`t` is an alias for the table, ActiveRecord adds it.
What request was generated in the second case?

I
index0h, 2015-01-09
@index0h

But the most important thing is how to make this criterion work?

Your filtering fields are added to order and will be added after the ORDER BY statement in the resulting query, as is. `t` is an alias of the main table against which the query is being made.
What you need (sortField - the field by which sorting is required, in principle, multiple filtering can also be used):
$criteria->order = '`t`.`sortFeild` ASC';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question