通过选择codeigniter 3.0中的选项显示结果 [英] Display result by selecting option in codeigniter 3.0

查看:120
本文介绍了通过选择codeigniter 3.0中的选项显示结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看图片
实际上,当我选择商家ID和年份时显示结果,但如何使用该选择按钮可以帮助我解决问题

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

这是我的模型

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;
    }

}

p>

And This is my Controller

 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

Merchant 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 }?>


推荐答案

我不完全确定我是否正确理解,这里是我认为你想做的。首先,您将需要调整您的Model函数以接受另一个可选参数。

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.

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();
}

一旦你这样做,你将不得不提供选择框您的视图名称属性(和理想的ID属性)。示例:

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">

和...

<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:

public function overviews()
{
    $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.

这篇关于通过选择codeigniter 3.0中的选项显示结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆