如何根据情况加载视图页面

时间:2018-11-17 07:39:19

标签: php codeigniter if-statement

我有两个单选按钮和一个复选框。.如果仅选中单选按钮,我要加载一个视图页面(Receipt_view)如果同时选中了单选按钮和复选框,我想加载另一个视图页面(Receipt_View1) ...我的问题是,如果同时选中了单选按钮和复选框,我将得到2个视图页面的输出(即,两个视图页面均已加载,Receipt_view和Receipt_view 1都加载了),但是我希望在两个单选按钮和复选框已选中。 控制器代码:

RNWD_NO

HTML页面:

    if ($this->input->post('all'))
        {
        $this->db->where('date >=', $newDate);
        $this->db->where('date <=', $newDate2);
        $this->db->select('*');
        $this->db->from('purchasebill');
        $this->db->order_by("date", "asc");
        $this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
  $query = $this->db->get()->result_array();
        $data['query'] = $query;
        $this->load->view('Receipt_View', $data);

}

    if($this->input->post('all'))
    {
        if($this->input->post('item')){

        if ($this->input->post('all'))
        {
            if($this->input->post('item')){
            $this->db->where('billdate >=', $newDate);
        $this->db->where('billdate <=', $newDate2);
        $this->db->select('vno,Prdtname,Qty,bundle');
        $this->db->from('purchaseitem');
            $this->db->order_by("vno", "asc");
            //$this->db->join('purchasebill', 'purchasebill.no = purchaseitem.billno','left outer');
            //$this->db->join('parmaster','parmaster.pcode = purchasebill.partyname');
            $this->db->join('itemmaster','itemmaster.itcode = purchaseitem.Product_Code','left outer');
            $query = $this->db->get('')->result_array();
            $data['query'] = $query;
            $this->db->where('date >=', $newDate);
            $this->db->where('date <=', $newDate2);
            $this->db->select();
            $this->db->from('purchasebill');
            $this->db->order_by('voucherno');
            $this->db->group_by('voucherno');
            $this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
            $query = $this->db->get('')->result_array();
            $data['query1'] = $query;
            $this->load->view('Receipt_View1',$data);

    }}
if($this->input->post('selected'))
    {

        if($name = $this->input->post('businessType'))
        {
            $this->db->where('date >=', $newDate);
        $this->db->where('date <=', $newDate2);
        $this->db->where('PName',$name);
        $this->db->select('*');
        $this->db->from('purchasebill');
        $this->db->order_by("date", "asc");
        //$this->db->join('salesbill', 'salesbill.no = salesitem.billno','left outer');
        $this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
        $query = $this->db->get('')->result_array();
  $data['query'] = $query;
  $this->load->view('Receipt_View', $data);

      }
}

所有并选中的是单选按钮的名称,项目是复选框的名称。帮助我解决此问题。

3 个答案:

答案 0 :(得分:0)

您没有告诉我们在未选中这两个选项时会发生什么情况,因此我在这里没有提及这种情况,但是您可以执行以下操作:

if ($this->input->post('all')) {
    //do something with purchasebill, no need to repeat the code
    //check if the checkbox is checked:
    if($this->input->post('item')) {
       // do something with purchaseitem
       $this->load->view('Receipt_View1',$data);
    } else {
       $this->load->view('Receipt_View',$data);
    }
}

答案 1 :(得分:0)

在'else'块中写入函数,如果条件不使用'else'。

答案 2 :(得分:0)

通过使用elseif和&&运算符,我们可以根据条件加载

    if ($this->input->post('all'))
        {
        $this->db->where('date >=', $newDate);
        $this->db->where('date <=', $newDate2);
        $this->db->select('*');
        $this->db->from('purchasebill');
        $this->db->order_by("date", "asc");
        $this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
  $query = $this->db->get()->result_array();
        $data['query'] = $query;
        $this->load->view('Receipt_View', $data);

}

    else if(($this->input->post('all')) &&($this->input->post('item')))
    {




        $this->db->select('vno,Prdtname,Qty,bundle');
        $this->db->from('purchaseitem');
            $this->db->order_by("vno", "asc");
            $this->db->join('itemmaster','itemmaster.itcode = purchaseitem.Product_Code','left outer');
            $query = $this->db->get('')->result_array();
            $data['query'] = $query;
            $this->load->view('Receipt_View1',$data);

    }}
else if($this->input->post('selected'))
    {

        if($name = $this->input->post('businessType'))
        {
            $this->db->where('date >=', $newDate);
        $this->db->where('date <=', $newDate2);
        $this->db->where('PName',$name);
        $this->db->select('*');
        $this->db->from('purchasebill');
        $this->db->order_by("date", "asc");
        //$this->db->join('salesbill', 'salesbill.no = salesitem.billno','left outer');
        $this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
        $query = $this->db->get('')->result_array();
  $data['query'] = $query;
  $this->load->view('Receipt_View', $data);

      }
}