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条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大