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 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog