gpt4 book ai didi

php - 如何更新 CodeIgniter 更新中的特定字段?

转载 作者:行者123 更新时间:2023-11-29 01:27:45 24 4
gpt4 key购买 nike

我正在为 easyappointments.org 库使用 CodeIgniter 框架。我正在尝试通过行的 id 更新字段 data 。实际上这是我的更新代码:

return  $this->db
->update('ea_appointments', $appointment)
->where('ea_appointments.id', $appointment_id);

问题是 update 方法需要两个参数(要更新的表,与数据库字段名称列的关联数组)。在我上面的函数中,我只传递了 $appointment_id,所以变量 $appointment 是空的,不包含任何关联数组。我想知道如何仅将字段 data 更新为 1。并保持其他字段在相同的值条件下。这是表的结构:

id|book|start|end|notes|hash|unavailable|provider|data

逻辑示例:

上一个条件行:

id => 0
book => example
start => 18/10/2015
end => 19/10/2015
notes => empty
hash => akdjasldja
unavailable => false
provider => 5
data => 0

我用 0 值传入函数 $appointment_id。我正在等待这个新结果:

id => 0
book => example
start => 18/10/2015
end => 19/10/2015
notes => empty
hash => akdjasldja
unavailable => false
provider => 5
data => 1

所以主要问题是首先检索特定行的所有字段值然后更新?或者像这样的东西。有人可以帮助我吗?

最佳答案

In my above function I pass only the $appointment_id, so the variable $appointment is empty and doesn't contain any associative array.

如果您只想更新列 data1对于 appointment_id 0然后传入一个数组 data对于 key 和 1的值(value)。

$appointment_id = 0;
$appointment = array('data' => 1);
$this->db->where('id', $appointment_id);
$this->db->update('ea_appointments', $appointment);

关于php - 如何更新 CodeIgniter 更新中的特定字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33199160/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com