donglinxi1467 2015-08-11 05: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 05: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条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥100 二维码被拦截如何处理
  • ¥15 怎么解决LogIn.vue中多出来的div
  • ¥15 优博讯dt50巴枪怎么提取镜像
  • ¥30 在CodBlock上用c++语言运行
  • ¥15 求C6748 IIC EEPROM程序固化烧写算法
  • ¥50 关于#php#的问题,请各位专家解答!
  • ¥15 python 3.8.0版本,安装官方库ibm_db遇到问题,提示找不到ibm_db模块。如何解决?
  • ¥15 TMUXHS4412如何防止静电,
  • ¥30 Metashape软件中如何将建模后的图像中的植被与庄稼点云删除
  • ¥20 机械振动学课后习题求解答
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部