Welcome Guest, Not a member yet? Register   Sign In
Newbie help with database issue
#1

[eluser]Unknown[/eluser]
Hi there Smile

I'm rather new to php and even newer to Codeigniter. I'm building a site and I ran into a snag.

My users table has a field called "role_id". This is a foreign key from a table "roles" which has just 2 fields (id and role). My problem is that when a user is created, they must select their role from a dropdown menu. I can get their role (the actual name "boss" or "grunt") but I need to get the id of that role from the table "roles", and that I know not how to do.

I use this for getting the actual role
Code:
$role = $this->input->post('role');

Tried this for the ID but it doesnt work
Code:
$q = "SELECT id FROM roles WHERE role = ".$role."";
$role_id = $this->db->query($q);

This all happens in my Users_model.
#2

[eluser]Frank Rocco[/eluser]
Store the roldId in the dropdown box.
Code:
$dropdowns = $query->results();
            foreach($dropdowns as $dropdown)
            {
                $dropDownList[$role->ID] = $dropDown->RoleName;
             }




Theme © iAndrew 2016 - Forum software by © MyBB