我正在使用Yii php,我在数据库中遇到重复条目的问题。
要证明,假设我有这个:
id(pk) | parent_id | parent_name| is_male(boolean) | is_female(boolean)
------------------------------------------------------------------------
1 | 1 |parent1 | true | false
------------------------------------------------------------------------
2 | 1 |parent1 | false | true
------------------------------------------------------------------------
3 | 2 |parent2 | false | true
------------------------------------------------------------------------
从技术上讲,parent1是相同的,但用作女性和男性。 以上是正确的但效率低下,复制不是必需的,因为它们只属于同一个父级。我如何删除重复的parent1 并将第一行 is_female 更新为 true ?
导致:
id(pk) | parent_id | parent_name| is_male(boolean) | is_female(boolean)
------------------------------------------------------------------------
1 | 1 |parent1 | true | true
------------------------------------------------------------------------
3 | 2 |parent2 | false | true
------------------------------------------------------------------------
如何在Yii php中以编程方式执行此操作?谢谢!
答案 0 :(得分:0)
in update mode loadModel query change means you no need to delete the duplicated , the first record will be get updated
Controller file
----------------
Function loadModel($id)
{
$where='id='.$id .' Group by parent_id '
$model=Model()->find($where);
}
in view file
------------
<?php
if($model->parent_id==1) // when the parent_id is 1 the female field will visible , sure not affect the created
{
echo $form->textField($model, 'is_female'); ?>
}
?>