donglu6805 2018-05-09 02:50
浏览 60
已采纳

需要使用datatable_json显示获取数据,这些数据由用户在codeigniter中添加

I am working on a UNILEVEL MLM project & required to fetch data of users which is add by user. something went wrong in this code if i put $wh[] = "mobile_no = referred_by_id"; there is showing 1 result randomly but i need to verify through session. In this i used Mobile_no in session & in form of add member get entry of mobile no in referred_by_id. I need to show if session mobile no. matched in referred_by_id show all data there is showing only 1 randomly. Please help me

Model

public function get_all_users(){
        $wh =array();
        $SQL ='SELECT * FROM ci_users';
        $wh[] = "$this->session->userdata('mobile_no') = referred_by_id";
        if(count($wh)>0)
        {
            $WHERE = implode(' and ',$wh);
            return $this->datatable->LoadJson($SQL,$WHERE);
        }
        else
        {
            return $this->datatable->LoadJson($SQL);
        }
    }

Controller

public function datatable_json(){                                      
        $records = $this->user_working->get_all_users();
        $data = array();
        foreach ($records['data']  as $row) 
        {  
            $status = ($row['is_active'] == 0)? 'inactive': 'active'.'<span>';
            $disabled = ($row['is_admin'] == 1)? 'disabled': ''.'<span>';
                            $data[]= array(
                ucfirst($row['firstname']),
                $row['email'],
                date('F j, Y',strtotime($row['created_at'])),
                '<span class="btn bg-teal  waves-effect" title="status">'.getGroupyName($row['role']).'<span>', // get Group name by ID (getGroupyName() is a helper function)
                '<span class="btn bg-blue  waves-effect" title="status">'.$status.'<span>',         

                '<a title="Delete" class="delete btn btn-sm btn-danger pull-right '.$disabled.'" data-href="'.base_url('user/users/del/'.$row['id']).'" data-toggle="modal" data-target="#confirm-delete"> <i class="material-icons">delete</i></a>
                <a title="View" class="view btn btn-sm btn-info pull-right" href="'.base_url('user/users/edit/'.$row['id']).'"> <i class="material-icons">visibility</i></a>',

            );
        }
        $records['data']=$data;
        echo json_encode($records);                        
    }
  • 写回答

1条回答 默认 最新

  • douren7179 2018-05-09 04:22
    关注

    The session could not be converted to the string & you are passing the session value to the column to check in the query

    update your $wh[] by the following code

    $wh[] = "`referred_by_id` = '{$this->session->userdata('mobile_no')}'";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 输出区间内所有的完数的个数。 要简单点的程序
  • ¥15 asp.core 权限控制怎么做,需要控制到每个方法
  • ¥20 while循环中OLED显示中断中的数据不正确
  • ¥15 这个视频里的stm32f4代码是怎么写的
  • ¥15 串口发送数据和接收数据
  • ¥15 JNA调用DLL报堆栈溢出错误(0xC00000FD)
  • ¥15 请教SGeMs软件的使用
  • ¥15 自己用vb.net编写了一个dll文件,如何只给授权的用户使用这个dll文件进行打包编译,未授权用户不能进行打包编译操作?
  • ¥50 深度学习运行代码直接中断
  • ¥20 需要完整的共散射点成像代码