如何在codeigniter中为``FROM_UNIXTIME`正确地“GROUP BY”?

时间:2015-12-22 13:09:38

标签: mysql codeigniter

到目前为止,我已尝试过这段代码:

Console.WriteLine((this.dataGridView1.DataSource as DataTable).Locale.DateTimeFormat.ShortDatePattern);

但是得到了这样的错误:

$this->db->group_by('FROM_UNIXTIME(mec.dt_start,"%Y-%D-%M"');

任何人都有想法如何解决这个问题?

额外信息:

GROUP BY FROM_UNIXTIME(mec.dt_start, `"%Y-%D-%M")`

Notes(我的自定义数据库帮助程序):

function get_events_data($limit='',$offset='',$type='calendar')
{
    $search_input = $this->session->userdata('search_input');
    $this->db->set_dbprefix('');

    db_select('mu.fullname');
    db_select('mu.username');
    db_select('me.event_id');
    db_select('me.user_id');
    db_select('me.user_type');
    db_select('me.event_name');
    db_select('me.url_id');
    db_select('me.event_details');
    db_select('me.is_payment_required');
    db_select('mec.remarks');
    db_select('mec.fee');
    db_select('mec.max_pax');
    db_select('mec.bal_pax');
    db_select('mec.deleted_status');
    db_select('mec.calendar_id');
    db_select('mec.event_state_id');
    db_select('mec.venue_location');
    db_select('mec.dt_start,mec.dt_end');
    db_select('mec.approval_status,mec.deleted_status');
    db_where('mec.dt_start >= ',time());
    db_where('mec.dt_start <=',strtotime(MAX_TIME_EVENT_CALENDAR_DISPLAY));
    db_join('m_event_calendar mec','mec.event_id=me.event_id','left');
    db_join('m_users mu','mu.user_id=me.user_id','left');
    if($type=='event_list' || $type == 'url_id'):
        db_group('FROM_UNIXTIME(mec.dt_start,"%Y-%D-%M")');
    endif;
    db_order('FROM_UNIXTIME(mec.dt_start)','asc');
    if($this->curuser):
        db_where('(me.user_id = '.$this->curuser['user_id'].' or me.approval_status = '.EVENT_APRROVAL_STATUS_APPROVED.')');
    else:
        db_where('me.approval_status',EVENT_APRROVAL_STATUS_APPROVED);
    endif;
    db_where('mec.deleted_status',EVENT_DELETED_STATUS_NO);
    if(!empty($search_input)):
        $this->db->like('me.event_name', $search_input,'match');
        $this->db->or_like('me.venue_location', $search_input,'match');
    endif;
    if($limit == '' || $offset == ''):
        $sql = db_get('m_event_list me');
    else:
        $sql = db_get('m_event_list me', $limit,  uri_segment($offset));
    endif;      

    $array = $sql->result_array();

    $this->db->set_dbprefix('m_');
    if($array):
        return $array;
    endif;
}

2 个答案:

答案 0 :(得分:0)

尝试检查以下内容:

$this->db->group_by('FROM_UNIXTIME(mec.dt_start,"%Y-%D-%M")',FALSE);

答案 1 :(得分:0)

最后,我通过添加此代码获得了答案

Requirement already satisfied (use --upgrade to upgrade): numpy in <insert folder name here>

在开始我的查询之前。

$this->db->_protect_identifiers=false;

感谢所有人帮助我。希望它能帮助别人。