Sql server 通过选择codeigniter 3.0中的选项显示结果
实际上,当我选择商户id和年份时,我想显示结果,但如何使用选择按钮,任何人都可以帮助我解决问题吗Sql server 通过选择codeigniter 3.0中的选项显示结果,sql-server,codeigniter,Sql Server,Codeigniter,实际上,当我选择商户id和年份时,我想显示结果,但如何使用选择按钮,任何人都可以帮助我解决问题吗 <?php $merchanttype=$this->livemerchant_model->merchant_type_dropdown(); foreach ($merchanttype as
<?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 }?>
这是我的模型
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;
}
}
<?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 }?>
这是我的控制器
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);
}
<?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 }?>
这是我的视图文件
<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>
<?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 }?>
选择一年
我不完全确定我是否正确理解了这一点,但以下是我认为你想要做的。首先,需要调整模型函数以接受另一个可选参数
<?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 }?>
function overviews($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();
}
一旦这样做了,您就必须为视图中的选择框提供一个name属性(理想情况下是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 }?>
<select name="transactionYear" id="transactionYear" aria-required="true" required="required">
这会给你你想要的。希望这有帮助。将商户id和年份传递到控制器函数中,并使用where子句在模型函数中过滤结果行。要传递值,您可以使用表单提交或javascript。感谢@cfnerd的回复,基本上我是codeigniter的新手,但当我在选择id和result后进行subit时没有运气,因为我的查看页面处于选项卡状态
<?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 }?>