CodeIgniter Forums

Full Version: returning the present primary key
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]rochellecanale[/eluser]
Hey guys i need a little help. All i want is to retrieve my member_id to pass it in the other table i tried to use the $this->db->insert_id(); but it returns to 0. But when i look up in the table the ID value is 8. How can i get the value of 8 in my other table? Because im trying to run two queries in one execution. Here's my sample code.
Code:
$member = array(
                    'member_id' => null,
                    'account_type' => $this->input->post('mem_type'),
                    'username' => strtolower($this->input->post('username')),
                    'account_type' => $this->input->post('mem_type'),
                    'lastname' => ucwords($this->input->post('lastname')),
                    'firstname' => ucwords($this->input->post('firstname')),
                    'middlename' => ucwords($this->input->post('middlename')),
                    'gender' => $this->input->post('gender'),
                    'email' => strtolower($this->input->post('email')),
                    'mobile_number' => $this->input->post('contact'),
                    'password' => md5($this->input->post('password')),
                    'upline' => $this->input->post('referral'),
                    'account_created' => date('Y-m-d h:i:s')
                );
                $member_insert_id = $this->db->insert_id();
                
                $id = $this->input->post('referral');
                
                //count the selected id in upline
                $this->db->like('upline',$id);
                $this->db->from('member');
                $query =  1 + $this->db->count_all_results();  
                
                $this->member = 0;
                
                if($query < $this->reglvl1){
                    $this->member = 1;
                }
                
                if($query < $this->reglvl2){
                    $this->member = 2;
                }
                
                if($query < $this->reglvl3){
                    $this->member = 3;
                }
                
                if($query < $this->reglvl4){
                    $this->member = 4;
                }
                
                if($query < $this->reglvl5){
                    $this->member = 5;
                }
                
                $insert_downline = array(
                    'down_id' => null,
                    'level' => $this->member,
                    'fkmember' => $id, //referral id
                    'downline' => $member_insert_id //member id
                    );
                    
                return $this->db->insert('downline',$insert_downline);
                return $this->db->insert('member',$member);

El Forum

[eluser]siptik[/eluser]
HI! In a function you can use one return value! it's first.
Second:
"$this->db->insert_id()" should be used after "$this->db->insert()"!
Sorry, my English is bad.