代码点火器错误消息重复条目


Codeigniter error message Duplicate entry

我正在尝试实现Php Codeigniter模型函数,该函数可以计算二叉树的左子级和右子级的数量,但我收到了以下消息错误:

错误编号:1062

键1的重复条目"4"INSERT INTO"mytable"(members_idmembers_usernamemembers_password,)文件名:C: ''AppServ''www''app''system''database''DB_driver.php

线路编号:330

我使用这个函数,我想我有一些逻辑错误。

function count(){
 $query = $this->db->get('mytable');
foreach ($query->result() as $row) {
 if ($row->id > 1) {
  $Right_Child= $this->insert_to_right($row, $row->id);
  $Left_child = $this->insert_to_left($row, $row->id);
$count1=0;
    $count2=0;
if($Left_child!=NULL){
        for($count1;$count1<=10;$count1++)
            {
       $count1=$htis->Left_child->count();
            echo 'Left_child';
        }
        if($Right_Child!=NULL){
            for($count2;$count2<=10;$count2++){
            $count2= $this ->Right_Child->count();
            return $count2;
            echo 'Right_Child';
            if($count1==$count2){
                echo'tree';
            }
            }
        }
    }
        }
阿明·阿达所指出的是正确的。

将记录插入数据库时,请尝试省略记录的ID,或者将其设置为NULL。

在这种情况下,ID字段显示为"members_ID"

您在某个位置插入时出现问题。

尝试将自动递增添加到member_id

 ALTER TABLE mytable ADD members_id INT PRIMARY KEY AUTO_INCREMENT;

删除旧数据后重试。

如果您对id使用Integer,请尝试将类型字段member_idint->PRIMARY更改为varchar->PRIMARY,并且不要在数据库

上使用自动增量