gpt4 book ai didi

php - yii:if 和 else 在 ajax 和 foreach 中

转载 作者:搜寻专家 更新时间:2023-10-31 21:09:26 25 4
gpt4 key购买 nike

当我在我的代码中添加 elseif 无法正常工作,并且只会处理数组的第一部分

Array ( [0] => php [1] => yii9 [2] => milsss [3] => msa [4] => klk )

在此仅选中 php!

   foreach ($columnsArray as $u)
{
$masterCommand = Yii::app()->db->createCommand();
$gname=$this->group;
if($this->group == $u)
{
$this->addError('group' ," $gname already registered");
$masterCommand->reset();
$masterCommand->insert('group',array(
$this->group=>'1',
));
$masterCommand->reset();
$this->newId= $masterCommand->select('max(id)')->from('group')->queryAll();
$this->newId= $this->newId[0]['max(id)'];
break;
}

这是else

  else {
$this->addError('group' ," $gname not registered");
break;
$masterCommand->reset();
$masterCommand->addColumn('group' , $gname , 'int(1)');
$masterCommand->reset();
$masterCommand->insert('group', array(
$this->group=>'1',
));
$masterCommand->reset();
$this->newId = $masterCommand->select('max(id)')->from('group')->queryAll();
$this->newId= $maxId[0]['max(id)'];
}
}

在这两个部分中,我如何进行更改?

最佳答案

必须先清除错误 然后稍后再次显示 AddError

 if ($this->group == $u)
{
$this->clearErrors('group');
$this->addError('group' ," $gname already registered");
$masterCommand->reset();
$masterCommand->insert('group',
array
(
$this->group=>'1',
));
$masterCommand->reset();
$this->newId=$masterCommand->select('max(id)')->from('group')->queryAll();
$this->newId=$this->newId[0]['max(id)'];
$test_status=TRUE;
continue;
}
if($test_status==FALSE)
{
$this->clearErrors('group');
$this->addError('group' ," $gname not registered");
continue;
}

关于php - yii:if 和 else 在 ajax 和 foreach 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24206500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com