嘿伙计们,我需要一点帮助。我想要的只是检索我的 member_id 以将其传递到我尝试使用的另一个表中 $this->db->insert_id(); 但它返回 0。但是当我在表中查找时,ID 值为 8。如何在我的另一个表中获得 8 的值?因为我试图在一次执行中运行两个查询。这是我的示例代码。
$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,它将自动添加到该成员并在上线字段中插入一个“无”值。参考 ID 来自推荐使用以拥有会员资格的人。如果成员有一个参考 id,它也会添加到成员表和下线表中。但是下线表将验证用户是否是什么级别。我在水平查找方面没有问题。我的问题在我的下线专栏中。它总是存储到来自 $this->db->inser_id() 的值 0。我怎样才能获得正确的值?请帮帮我。