Php 使用此选项获取月份和年份->;db->;codeigniter在哪里

Php 使用此选项获取月份和年份->;db->;codeigniter在哪里,php,mysql,codeigniter,codeigniter-3,Php,Mysql,Codeigniter,Codeigniter 3,在我的项目中仍然存在问题。我自己以前的帖子,但没有答案。我想打电话给mysql数据库的年和月的数据帖子的结果 这是我的控制器 public function report(){ $nomor = $this->input->post('nomor_reseller'); $bulan = $this->input->post('month'); // YYYY-MM $report_data = $this->hasil_m->get_data($nomor

在我的项目中仍然存在问题。我自己以前的帖子,但没有答案。我想打电话给mysql数据库的年和月的数据帖子的结果

这是我的控制器

public function report(){
$nomor = $this->input->post('nomor_reseller');
$bulan = $this->input->post('month'); // YYYY-MM

$report_data = $this->hasil_m->get_data($nomor, $bulan );
}
如果只有那个叫她工作的月份,但如果我进入了那个年,那个月就没有工作了

这是我的模特

function get_data($nomor,$bulan) {
    $this->db->select('*');
    $this->db->from('tb_pelanggan as pel');
    $this->db->join('tb_produk as pro', 'pel.id_barcode  = pro.id_barcode');    
    $this->db->select_sum('jumlah');
    $this->db->where('MONTH(pel.tgl_pembelian)',$bulan);
    $this->db->group_by('pel.id_barcode');
    $query = $this->db->get();
    if ($query->num_rows() > 0) {
        return $query->result();
        } else {
        return false;
    }
}   
首先是你的控制器

public function report(){
$nomor = $this->input->post('nomor_reseller');
$bulan = $this->input->post('month'); // MM
$tahun = $this->input->post('year'); // YYYY

$report_data = $this->hasil_m->get_data($nomor, $bulan, $tahun );
}
你的模特呢

function get_data($nomor,$bulan,$tahun) {
    $this->db->select('*');
    $this->db->from('tb_pelanggan as pel');
    $this->db->join('tb_produk as pro', 'pel.id_barcode  = pro.id_barcode');    
    $this->db->select_sum('jumlah');
    $this->db->where('MONTH(pel.tgl_pembelian)',$bulan);
    $this->db->where('YEAR(pel.tgl_pembelian)',$tahun);
    $this->db->group_by('pel.id_barcode');
    $query = $this->db->get();
    if ($query->num_rows() > 0) {
        return $query->result();
        } else {
        return false;
    }
}   
首先是你的控制器

public function report(){
$nomor = $this->input->post('nomor_reseller');
$bulan = $this->input->post('month'); // MM
$tahun = $this->input->post('year'); // YYYY

$report_data = $this->hasil_m->get_data($nomor, $bulan, $tahun );
}
你的模特呢

function get_data($nomor,$bulan,$tahun) {
    $this->db->select('*');
    $this->db->from('tb_pelanggan as pel');
    $this->db->join('tb_produk as pro', 'pel.id_barcode  = pro.id_barcode');    
    $this->db->select_sum('jumlah');
    $this->db->where('MONTH(pel.tgl_pembelian)',$bulan);
    $this->db->where('YEAR(pel.tgl_pembelian)',$tahun);
    $this->db->group_by('pel.id_barcode');
    $query = $this->db->get();
    if ($query->num_rows() > 0) {
        return $query->result();
        } else {
        return false;
    }
}   

为什么不直接使用日期格式而不是年和月

->where("DATE_FORMAT(column_name,'%Y-%m')", $bulan)

为什么不直接使用日期格式而不是年和月

->where("DATE_FORMAT(column_name,'%Y-%m')", $bulan)

所以你能澄清一下:这个
$bulan=$This->input->post('month')
包含一个类似于
2016-03
的值,对吗?是的,非常精确@RiggsFolly,过去2年的邮政月和一个月值,因此您可以澄清一下:This
$bulan=$This->input->POST('month')
包含一个类似于
2016-03
的值,对吗?是的非常精确@RiggsFolly,POST month过去2年,month valuenice@Suhindra,但我只使用1个输入POST,仅使用1个月,仅使用1个输入POST和DatePickernie@Suhindra