在yii2中更新查询

时间:2015-08-24 12:40:16

标签: yii2

我有一个表单,用户可以为产品输入不同的价格。用户也可以更新价格。表单如下所示: enter image description here

我有两个数组,其中一个是Id,另一个是Prices

到目前为止,我已经能够达到这个目标......

if(isset($_POST['addprice']))
{
    $id = $_REQUEST['id'];
    $price = $_REQUEST['price'];
    foreach ($price as $key => $val) {
        $priceds=$price[$key];
        $idds=$id[$key]; 
        if(!empty($priceds)){ 
            $command = $connection->createCommand('UPDATE businessitemots SET price='.$priceds.' WHERE id='.$idds.'');
            $command->execute();
        }
    }
    $this->redirect('index',[
        'searchModel' => $searchModel,
        'dataProvider' => $dataProvider
    ]);
}

我的问题是数据库中的值没有得到更新。你能指出我正确的方向吗?

0 个答案:

没有答案