Reputation: 21
I am using Yii framework.
/view/update.php
<?php
echo CHtml::beginForm();
foreach ($items as $i=>$item):
echo '<tr>';
echo '<td>'.$item['name'].'</td>';
echo '<td>'.$item['c1'].'</td>';
echo '<td>'. count(cos::model()->findAll(array(
'condition'=>'cos2='.$item['id'],))).'</td>';
echo '<td>'. CHtml::activeCheckBox($item, "[$i]c2").'</td>';
echo '<td>'. CHtml::activeCheckBox($item, "[$i]c3").'</td>';
echo '<td>'. CHtml::activeCheckBox($item, "[$i]c4").'</td>';
echo '<td>edit</td>';
echo '</tr>';
endforeach;
echo '</table>';
echo CHtml::submitButton('Save');
echo CHtml::endForm();
?>
how can I write all the records at once?
Upvotes: 1
Views: 9185
Reputation: 644
In Yii2, if you are using a Bind Variable (which is recommended) then use the below syntax. In the e.g. Sometable's tr_id and completeby_dt are updated to Null where column tr_id = variable $tr_id.
Sometable::updateAll(['tr_id' => NULL, 'completeby_dt' => NULL],
'tr_id = :vtrid', [':vtrid' => $tr_id]);
Upvotes: 0
Reputation: 139
you can use this as reference on how to use the Yii update all
CActiveRecord::updateAll($attributes, $condition='', $params=array())
http://www.saidur-rahman.com/yii-how-to-updateall-works/
Upvotes: 1
Reputation: 6297
Use updateAll
As an example
User::model()->updateAll(array( 'status' => 1, 'updated' => date('Y-m-d' ),
'type_id = 1 AND status = 0 '
);
Upvotes: 1