Display Result By Selecting Option In Codeigniter 3.0
view image Actually when i select merchant id and year i want to display result, but how to use that select button can any one help me resolve the issue This is my model function o
Solution 1:
I am not entirely sure I understand this correctly, but here is what I think you want to do. First, you will need to adjust your Model function to accept another optional parameter.
functionoverviews($theMerchant = '', $theYear = '', $theMonth = '')
{
$this->db->select("DATEPART(Year, TRANS_TransactionDate) [TheYear], DATEPART(Month, TRANS_TransactionDate) [TheMonth], DATENAME(Month, TRANS_TransactionDate) [TheMonthName], SUM(TRANS_Amount) [TotalAmount]", false);
$this->db->from('BTBL_Transactions');
if ($theYear != '') {
$this->db->where("DATEPART(Year, TRANS_TransactionDate) = '" . $theYear . "'", NULL, FALSE);
}
if ($theMonth != '') {
$this->db->where("DATEPART(Month, TRANS_TransactionDate) = '" . $theMonth . "'", NULL, FALSE);
}
if ($theMerchant != '') {
$this->db->where("TRANS_MerchantId", $theMerchant);
}
$this->db->group_by("DATEPART(Year, TRANS_TransactionDate), DATEPART(Month, TRANS_TransactionDate), DATENAME(Month, TRANS_TransactionDate)");
$this->db->order_by("1", "asc");
$this->db->order_by("2", "asc");
$this->db->order_by("3", "asc");
$query = $this->db->get();
return$query->result();
}
Once you do that, you are going to have to give the select boxes in your view a name attribute (and ideally an ID attribute). Examples:
<select name="transactionYear" id="transactionYear" aria-required="true"required="required">and...
<select name="transactionMerchant" id="transactionMerchant" aria-required="true"required="required">Once you do that, you can adjust your controller like below. In that, I am also showing you that it is likely better to pass your data into the view, rather than have your variables populated within the view:
publicfunctionoverviews()
{
$this->load->model('livemerchant_model');
$name=$this->session->userdata('name');
if ($this->input->post('transactionMerchant')) {
$data['monthlyTotals'] = $this->livemerchant_model->overviews($this->input->post('transactionMerchant'), $this->input->post('transactionYear'));
} else {
$data['monthlyTotals'] = $this->livemerchant_model->overviews();
}
$data['merchanttype'] = $this->livemerchant_model->merchant_type_dropdown();
$data['year'] = $this->livemerchant_model->Year_dropdown();
$this->load->view('overviews', $data);
}
This should give you what you want. Hope this helps.
Post a Comment for "Display Result By Selecting Option In Codeigniter 3.0"