I get all data from a table to a array :
$records = $this->Misc->getAll('table');
Next I made a loop
foreach ($records as $key => $record) {
// here i want to update a column in the fist
// row with a value from the second row
$this->Misc->update($record->id; $value_of_a_column_from_the_next_row);
}
How can I do this? Thanks
you can use your foreach loop like:
foreach ($records as $key => $record) {
if (isset($records[$key-1]) {
$updateID = $records[$key-1];
$this->Misc->update($updateID, $record['field'] );
}
}
or the other way around:
foreach ($records as $key => $record) {
if (isset($records[$key+1]) {
$updateID = $records[$key+1];
$this->Misc->update($updateID, $record['field'] );
}
}