douke6881 2019-02-23 06:03
浏览 65

如何显示连接的输出以及IF条件的输出?

I am using CodeIgniter. Below code, I am using in the model.

My issue is, I have to display the output of the join as well as I am using one more condition inside If condition that output I also need.

What I am doing is, I am fetching the records from the multiple tables and passing membershipForTheYear column name in the IF condtion.

membershipForTheYear output is the year range like 2018-2019.

I am breaking it using explode and changing from 2018-2019 to 2019-2020 to get the output from the table. Now I have to display the output of the this and joins on view.

Why I am doing this because I have to display the next year fees with above joins output.

Should I return two results or I have to use some array?

Would you help me out in this?

public function upcomingData(){
    $get_s_member = array('members.is_Approved'=>1,'members.is_status'=>1);
            $this->db->select('*');
            $this->db->from('members'); 
            $this->db->join('membership_details', 'members.member_id = membership_details.member_id','LEFT');
            $this->db->where($get_s_member);
            $this->db->group_by('membership_details.member_id'); 
            $this->db->order_by('membership_details.membership_added_date','DESC');

            $query = $this->db->get();
            $result   = $query->result();

         if($result)
        {
          foreach ($result as $key => $value) {
          $membershipForTheYear=explode('-',$value->membershipForTheYear);
                             $addNextyear=$membershipForTheYear[1] + 1;
                             $activeBTN=$membershipForTheYear[1].'-'.$addNextyear;

                      $where = array('Duration'=>$activeBTN,'is_FeesActive'=>1);
                      $result = $this->db->where($where)
                                             ->from('bMembershipFees')
                                             ->get()
                                             ->row();
                              // print_r($result);
          }
             return $result;  
        }
        else 
        {
           return 0;  
        }


      }
  • 写回答

1条回答 默认 最新

  • duangejian6657 2019-02-23 07:06
    关注
    public function upcomingData() {
        $respose_array = array();
        $get_s_member = array('members.is_Approved' => 1, 'members.is_status' => 1);
        $this->db->select('*');
        $this->db->from('members');
        $this->db->join('membership_details', 'members.member_id = membership_details.member_id', 'LEFT');
        $this->db->where($get_s_member);
        $this->db->group_by('membership_details.member_id');
        $this->db->order_by('membership_details.membership_added_date', 'DESC');
    
        $query = $this->db->get();
        $result = $query->result();
    
        if ($result) {
            foreach ($result as $key => $value) {
                $membershipForTheYear = explode('-', $value->membershipForTheYear);
                $addNextyear = $membershipForTheYear[1] + 1;
                $activeBTN = $membershipForTheYear[1] . '-' . $addNextyear;
    
                $where = array('Duration' => $activeBTN, 'is_FeesActive' => 1);
                $result1 = $this->db->where($where)
                        ->from('bMembershipFees')
                        ->get()
                        ->row();
                // print_r($result);
            }
            $respose_array[0] = $result;
            $respose_array[1] = $result1;
            return $respose_array;
        } else {
            return $respose_array = array(0=>'0',1=>'0');
        }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画