表資訊:
| 身份資料 | 身份證 | 筆記 |
|---|---|---|
| 1 | 5 | 我和約翰哈里森一起回家了 |
| 2 | 5 | 我和約翰哈里森共進晚餐 |
| 3 | 5 | 我和約翰哈里森一起去購物 |
| 4 | 3 | 我和約翰哈里森共進晚餐 |
我想在id-note (5) 的注釋中更新“ John Harrison ” ,使用“ Sebastian ”,但仍然使用codeigniter-3 model-controller
更新后的表資訊應為:
| 身份資料 | 身份證 | 筆記 |
|---|---|---|
| 1 | 5 | 我和塞巴斯蒂安一起回家了 |
| 2 | 5 | 我和塞巴斯蒂安共進晚餐 |
| 3 | 5 | 我和塞巴斯蒂安一起去購物 |
| 4 | 3 | 我和約翰哈里森共進晚餐 |
所有的建議都會很有幫助。
uj5u.com熱心網友回復:
我為你做了一個我認為對你有用的例子。
你需要找到并使用str_replace來改變你的筆記。見例子:
$findText = 'John Harrison';
$replaceText = 'Sebastian';
$this->db->select('*');
$this->db->from('test');
$this->db->where('id-note',5);
$query = $this->db->get();
$result = $query->result_array();
foreach($result as $val) {
$youText = $val['note'];
$replace_1 = ["$findText"];
$replace_2 = ["$replaceText"];
$result = str_replace($replace_1, $replace_2, $youText);
$updateText = array(
'note'=>$result
);
$this->db->where('id-data',$val['id']);
$this->db->update('info',$updateText);
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/464324.html
