[eluser]Unknown[/eluser]
The site I'm building needs to accommodate 3 different types of users. I'll be able to store some shared information about them in a general "users" table, but based on their type I'll need to store different data. So I've created separate tables for each user type so as to not end up with many empty fields in my user table.
There is a "user_type" field in my users table but I'm just not sure how to perform the necessary join based on their type.
Would it be best to retrieve basic user information and then perform a switch on the user's type to determine which table to join to and then run the proper query?
Code:
function userType($id) {
$q = $this->db->get_where('users', array('id' => $id));
if($q->num_rows() > 0) {
$row = $q->row();
switch ($row->user_type) {
case 0:
//Join with admin table, return result
break;
case 1:
//Join with mod table, return
break;
case 2:
//Join general user table, return
break;
}
}
}
Thanks in advance for your help!