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 对于知识的学以致用的解释
  • ¥50 三种调度算法报错 有实例
  • ¥15 关于#python#的问题,请各位专家解答!
  • ¥200 询问:python实现大地主题正反算的程序设计,有偿
  • ¥15 smptlib使用465端口发送邮件失败
  • ¥200 总是报错,能帮助用python实现程序实现高斯正反算吗?有偿
  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败