【发布时间】:2013-11-30 23:41:28
【问题描述】:
我正在尝试实现 Php Codeigniter 模型函数,该函数可以计算二叉树的左子节点数和右子节点数,但我收到此消息错误:
错误号:1062
键 1 INSERT INTO 'mytable' 的重复条目 '4' (
members_id,members_username,members_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 设置了唯一键(应该是,但你忘记将它设置为自动增量。)
-
我将它设置为自动增量,我得到了同样的错误。
-
问题是当你插入数据时..检查你的查询是否插入..如果你将自动增量设置为主键..让
members_id的值为null
标签: php codeigniter