我如何在此代码中使用order by(name)来获得asc命令的结果

时间:2017-04-12 06:16:56

标签: php sql sql-order-by

我如何在此代码中使用order by(name)来获得asc命令的结果?

这是一段代码:

function getRecordByID($id)
    {
        $this->db->select($this->tbl_area_menu.'.*,'.$this->tbl_users.'.firstname as created_by,'.$this->tbl_page.'.name as page_name,'.$this->tbl_page.'.slug as page_slug,'.$this->tbl_page.'.template_directory,'.$this->tbl_directory.'.slug as directory_slug');

        $this->db->where($this->tbl_area_menu.'.id',$id);
        $this->db->join($this->tbl_users,$this->tbl_users.'.id = '.$this->tbl_area_menu.'.created_by','left');
        $this->db->join($this->tbl_page,$this->tbl_page.'.id = '.$this->tbl_area_menu.'.page_id','left');
        $this->db->join($this->tbl_directory,$this->tbl_directory.'.id = '.$this->tbl_page.'.template_directory','left');


        $query = $this->db->get($this->tbl_area_menu);
        //echo $this->db->last_query();
        $record = $query->row();
        return $record;
    }

1 个答案:

答案 0 :(得分:0)

看起来您正在使用Query Builder。如果是这种情况,请在join之后添加$this->db->order_by('name', 'ASC');