【问题标题】:How to load the view page according to the condition如何根据条件加载视图页面
【发布时间】:2018-11-17 07:39:18
【问题描述】:

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

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

      }
}

HTML页面:

<input type="radio" class='rd'name="all" value="op1" checked="">All
<input type="radio" name="selected" class='rd' value="op2"> Selected
<input type="checkbox" name="item" >Item description

All and selected 是单选按钮名称,item 是复选框名称..帮我解决这个问题..

【问题讨论】:

    标签: php codeigniter if-statement


    【解决方案1】:

    你还没有告诉我们当它们都没有被检查时会发生什么,所以我在这里没有提到这种情况,但你可以这样做:

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

    【讨论】:

    • 您能更详细地解释您的评论吗?显示页面的 html 并将我们指向单选按钮和复选框。在您提到的一个收音机和一个复选框的问题中,我说的对吗?
    • 对不起,我说错了..我在我编辑的帖子中添加了html页面
    【解决方案2】:

    在 'else' 块中编写函数,你不要在 if 条件下使用 'else'..

    【讨论】:

    • 已尝试但结果获得了 2 个查看页面
    • 在加载第二个视图页面的if条件中再添加一个if条件
    • 试过,但它没有加载任何数据..结果我得到空白页......
    【解决方案3】:

    通过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);
    
          }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-31
      • 2013-04-17
      • 2014-08-07
      • 2023-03-30
      • 1970-01-01
      • 2010-11-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多