view image 其实当我选择商家ID和今年我想显示的结果,但是如何使用选择按钮可以在任何一个可以帮助我解决这个问题显示结果3.0
这是我的模型
function overviews($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);
}
$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();
}
public function merchant_type_dropdown(){
$this->db->distinct();
$this->db->select('TRANS_MerchantId');
$this->db->from('BTBL_Transactions');
$query= $this->db->get();
// echo $this->db->last_query();die();
if($query->num_rows()>0){
$result=$query->result();
return $result;
}
else{
return false;
}
}
public function Year_dropdown(){
$this->db->distinct();
$this->db->select('DATEPART(Year, TRANS_TransactionDate) [TheYear]');
$this->db->from('BTBL_Transactions');
$query= $this->db->get();
// echo $this->db->last_query();die();
if($query->num_rows()>0){
$result=$query->result();
return $result;
}
else{
return false;
}
}
,这是我的控制器
public function overviews()
{
$this->load->model('livemerchant_model');
$name=$this->session->userdata('name');
$data['monthlyTotals'] = $this->livemerchant_model- >overviews($theyear='');
$this->load->view('overviews', $data);
}
这是我的看法文件
<label class="tp-label">Select a year</label>
<select>
<?php $year=$this->livemerchant_model->Year_dropdown();
foreach ($year as $row){
?>
<option value="<?php echo $row->TheYear ?>"><?php echo $row->TheYear ?></option>
<!--- <option value="tier_two">MPOS</option>
<option value="tier_three">E-Commerce</option>
<option value="tier_four">Virtual Machine</option>--->
<?php }?>
</select>
商家ID
<?php $merchanttype=$this->livemerchant_model->merchant_type_dropdown();
foreach ($merchanttype as $merchant){
?>
<option value="<?php echo $merchant->TRANS_MerchantId ?>"><?php echo $merchant->TRANS_MerchantId ?></option>
<!--- <option value="tier_two">MPOS</option>
<option value="tier_three">E-Commerce</option>
<option value="tier_four">Virtual Machine</option>--->
<?php }?>
将商家ID和年份传递给控制器函数,并使用它来使用where子句过滤模型函数中的结果行。要传递这些值,您可以使用表单提交或JavaScript。 –