我想从db中获取一行,从行中删除一个元素,然后将该行更新回DB。
我写了这个代码
$query = $this->db->get_where(TABLENAME, array('pin_code' => $pincode), 1);
$result = $query->result_array();
$array = $result[0];
if (($key = array_search($ccode, $array)) !== false) {
unset($array[$key]);
} //$code is the value which i want to remove
$this->db->where('pin_code', $pincode);
$this->db->update(TABLENAME, $array);
这是行
Array (
[pin_code] => 854101
[ccode_1] => 5806
[ccode_2] =>
[ccode_3] =>
[ccode_4] =>
[ccode_5] =>
[ccode_6] =>
[ccode_7] =>
[ccode_8] =>
[ccode_9] =>
[ccode_10] =>
[ccode_11] =>
[ccode_12] =>
[ccode_13] =>
[ccode_14] =>
[ccode_15] =>
[ccode_16] =>
[ccode_17] =>
[ccode_18] =>
[ccode_19] =>
[ccode_20] =>
[ccode_21] =>
[ccode_22] =>
[ccode_23] =>
[ccode_24] =>
[ccode_25] =>
[ccode_26] =>
[ccode_27] =>
[ccode_28] =>
[ccode_29] =>
[ccode_30] =>
)
i我只想删除ccode_1(这不是固定取决于$ ccode value)值并将其更新回db,但并未如上显示所需的结果。
if (($key = array_search($ccode, $array)) !== false) {
$this->db->where('pin_code', $pincode);
$this->db->update(TABLENAME, array($key => ''));
}
ccode
和
pincode
中传递的所有值(在合格行中可能不止一个列)。
使用ccode
用substr_replace()
ccode_
。
I正在使用
array_reduce()
$this->db
- 它是对允许链链的活动记录方法(aka:
$qb
)的对象的引用。
querybuilder
$this->db
的值插入格式的字符串中作为int-type值(提高安全性);如果需要一个引用的字符串,那将是%2$d
的占位符。
$ccode
%1$s