donglinxi1467 2015-08-11 13:48
浏览 22
已采纳

如何在codeigniter中分别获取每个管理员创建的用户?

i have a Codeigniter system where Admin creates Reseller. So in reseller table values like name,country,phone,email,key,user_number, are stored. Whatever value is in user_number that much blank rows are created in users table. So reseller key is mapped to that user rows. if reseller asks for 10 user than 10 blank rows are created in user table mapped to his key.

Now once a reseller is created he can login and can edit his users i.e(he can fill in the user details)

Now my issues is that i want to fetch only the users mapped to currently loggedin reseller and not all the users in table. I dont know how to do this please help:

below is my Code where i fetch all the users for a reseller :

Controller:

public function index ()
{
    // Fetch all users


    $session_data = $this->session->userdata('logged_in');
    $id = $session_data['id'];

    $data['users'] = $this->user_m->get_users($id);


    // Load view
    $this->data['subview'] = 'reseller/user/index';
    $this->load->view('reseller/_layout_main', $this->data);


}

The Model function:

public function get_users(){

    $query = $this->db->get_where('users', array('key' => $id));   

    if($query -> num_rows() > 1)
    {
    return $query->result();
    }
    else
    {
   return false;
    }


   }

I have tried to fetch the users but got stucked with errors! please help me with code. i just need to show user mapped by key of reseller. So reseller should only see his own users and not others!

  • 写回答

3条回答 默认 最新

  • dongxia026531 2015-08-11 13:57
    关注

    You can set the a flag in db to know the reseller is logged in for example logged_in 1 and when the user will logout just make the logged_in to 0.

    that way when you fetching the reseller just use the condition array('key' => $id, 'logged_in' => 1).

    Hope that will help.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵