Irfan Alviansyah Irfan Alviansyah - 6 months ago 49
SQL Question

Codeigniter , syntax error, unexpected end of file, expecting function (T_FUNCTION)

this is my Controller

public function GetPostByDate($date){
$this->load->model('Super_Model');
$data['read_post'] = $this->Super_Model->get('t_post','status = "'.$date.'"');
$data['view']='v_bdate';
$this->load->view('index', $data);
}


Output


syntax error, unexpected end of file, expecting function (T_FUNCTION)

Answer

Just pass the data to model. In model function catch the variable and do the rest

Try this

In Controller

public function GetPostByDate($date){
    $this->load->model('Super_Model');
    $data['read_post'] = $this->Super_Model->get($date); # Changed 
    $data['view']='v_bdate';
    $this->load->view('index', $data);
}

In Model

public function get($date)
{
    $this->db->select(*);
    $this->db->where('tgl_post', $date); 
    $query = $this->db->get('t_post');
    $result = $query->result_array();
    return $result;
}