My database table is named ‘status’ and it has a column named ‘order’, which is of type float.
I’m trying to sort the status fields based on order from lowest to greatest and input those fields into a dropdown list.
This is the code I’m using:
echo $form->dropDownListRow($my_model, 'status', CHtml::listData(Status::model()->findAll(array('order'=>"'order' ASC")), 'id', 'name'), array('class'=>'span3','prompt'=>Yii::t('forms', 'Please Select A Status')));
But the list is always ordered by status ID. Do I need to do some type casting? If so, how would I typecast my query so that it orders by ‘order’ ascending?
You have specified the order incorrectly:
There are extra quotes around
order(the column name), which means that in effect you are not sorting at all. Remove the quotes to fix the problem, but put backticks in their place becauseorderis a reserved word in MySql: