mysql - Why is PHP updating the data not selected? -


hi i'm trying update column in table. i've selected range within column, , used foreach loop through them. however, noticed not updated range selected, outside selection. advice appreciated!

code:

$this->db->where('weekday', 5); $this->db->where('source', 'site');  $record = $this->db->get('user', 200);  $print_r($record->num_rows());  foreach ($record->result() $row) :     $data = array(         'weekday' => 1,     );      $this->db->where('user_id', $row->user_id); //added based on answer provided below     $this->db->update('user', $data);  endforeach; 

this indeed straightforward, , did print_r selected 200 rows.but code updated 3000 rows within table did not select in $record variable. how happen?

thanks,

update: many people tried , still failed track problem. pls think of way job done without using foreach?

thanks,

<?php  // select * 'user' 'weekday' = 5 , 'source' = 'site' limit 200 $this->db->where(['weekday' => 5, 'source' => 'site']); $record = $this->db->get('user', 200);  foreach($record->result() $row) {     // update 'user' set  'weekday' = 1 'user_id' = {$row->user_id}     $this->db->update('user', ['weekday' => 1], ['user_id' => $row->user_id]); }; 

try this, ps: don't quote me on code, time since coded last php


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -