Yii foreach错误?

时间:2015-10-19 12:55:24

标签: yii yii-extensions

我已经调用了一个函数。获取表号(result = 0)结果并更新相同的表值0到1.我正在使用更新query.i已运行此函数返回错误::缺少CDbCommand :: update()的参数2。

 public function newdisplaycontent()
{
    $count = Yii::app()->db->createCommand()
        ->select()
        ->from('scrolltable')
        ->where('result=:result', array(':result'=>0))
        ->queryAll();
$rs=array();
//print_r($count);

foreach($count as $item){
//process each item here
    $rs=$item['ID'];
    $user=Yii::app()->db->createCommand()
    ->update("scrolltable SET result = 1")
    ->where('ID=:id', array(':id'=>$rs));
}

return $rs;
}

感谢您的功能帮助..

1 个答案:

答案 0 :(得分:3)

update()的正确语法如下所示:

$user=Yii::app()->db->createCommand()
->update("scrolltable",array("result" => "1"))
->where('ID=:id', array(':id'=>$rs));

正如官方文件:

  

update()创建并执行UPDATE SQL语句。该方法将正确地转义列名并绑定要更新的值。

public integer update(string $table, array $columns, mixed $conditions='', array $params=array ( ))