php - Can't sort query results in ascending order -
i'm trying sort following select query in ascending order meds_name, can't figure out i'm doing wrong. it's instead sorting names start lower case letters first, , following start upper case.
query works when interpret , execute in mysql, not in yii. can see i'm going wrong:
$specs = yii::app()->db->createcommand() ->select("im.*,m.name meds_name,mf.name meds_freq_name, mr.name meds_route_name,mu.name meds_unit_name, concat_ws('/',im.meds_startmm,im.meds_startyyyy) meds_startdate, concat_ws('/',im.meds_endmm,im.meds_endyyyy) meds_enddate") ->from('indiv_meds im') ->leftjoin('meds m', 'im.meds_name=m.id') ->leftjoin('med_freq mf', 'im.meds_freq=mf.id') ->leftjoin('med_route mr', 'im.meds_route=mr.id') ->leftjoin('lkpmeds mu', 'im.meds_unit=mu.id') ->where($select_condition_declare) ->limit($limit, $start) ->order(array('meds_name asc')) ->queryall();
this because result sorting based on ascii code. can solve problem converting query result sorting column lowercase/uppercase:
$specs = yii::app()->db->createcommand() ->select("im.*, lower(m.name) meds_name,mf.name meds_freq_name, mr.name meds_route_name,mu.name meds_unit_name, concat_ws('/',im.meds_startmm,im.meds_startyyyy) meds_startdate, concat_ws('/',im.meds_endmm,im.meds_endyyyy) meds_enddate") ->from('indiv_meds im') ->leftjoin('meds m', 'im.meds_name=m.id') ->leftjoin('med_freq mf', 'im.meds_freq=mf.id') ->leftjoin('med_route mr', 'im.meds_route=mr.id') ->leftjoin('lkpmeds mu', 'im.meds_unit=mu.id') ->where($select_condition_declare) ->limit($limit, $start) ->order(array('meds_name asc')) ->queryall();
Comments
Post a Comment