嘿傢伙,我需要一點幫助。我想要的是檢索我的member_id在另一個表中傳遞它我試圖使用$ this-> db-> insert_id();但它返回到0.但是,當我在表中查找ID值是8.我怎樣才能得到我的另一個表中的8的值?因爲我試圖在一次執行中運行兩個查詢。這是我的示例代碼。檢索插入的ID Codeigniter
$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);
而我的另一個問題是當我在表中插入數據。它只插入第二個表中。這裏是我的表結構:
CREATE TABLE `member` (
`member_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`account_type` ENUM('REGULAR','DUPLICATE','CORPORATE','ADVANCE') NOT NULL,
`username` VARCHAR(30) NOT NULL,
`lastname` VARCHAR(50) NOT NULL,
`firstname` VARCHAR(50) NOT NULL,
`middlename` VARCHAR(50) NOT NULL,
`gender` ENUM('Male','Female') NOT NULL,
`email` VARCHAR(50) NOT NULL,
`mobile_number` VARCHAR(50) NOT NULL,
`password` VARCHAR(50) NOT NULL,
`upline` VARCHAR(10) NOT NULL,
`account_created` DATETIME NOT NULL,
PRIMARY KEY (`member_id`),
UNIQUE INDEX `username` (`username`),
UNIQUE INDEX `mobile_number` (`mobile_number`),
UNIQUE INDEX `email` (`email`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=3;
CREATE TABLE `downline` (
`down_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`level` INT(10) UNSIGNED NOT NULL,
`fkmember` INT(10) UNSIGNED NOT NULL,
`downline` INT(10) UNSIGNED NOT NULL,
PRIMARY KEY (`down_id`),
INDEX `fkmember` (`fkmember`),
CONSTRAINT `downline_ibfk_1` FOREIGN KEY (`fkmember`) REFERENCES `member` (`member_id`)
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=3;
我想先插入成員。如果成員沒有參考ID,它會自動添加到成員並在上線字段中插入值'none'。參考ID來自將用戶引入會員的人員。如果成員有一個引用ID,它也會添加到成員表和下線表中。但下線表將驗證用戶的級別是什麼。在查找關卡時我沒有問題。我的問題是在我的下線專欄中。它總是存儲到$ this-> db-> inser_id()的值0,我怎樣才能得到正確的值?請幫助我們。
好的,我會嘗試你的建議。希望它的工作。 – rochellecanale