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 echarts动画效果失效的问题。官网下载的例子。
  • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加