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!