gpt4 book ai didi

php - 使用 codeigniter 更新表列

转载 作者:行者123 更新时间:2023-11-29 10:10:35 25 4
gpt4 key购买 nike

大家好,我正在尝试使用 codeigniter 更新表列,这是我的代码如下。

Controller :

function search2()
{
if ($_POST) {
$Interno=$_POST['Interno'];
}else{
$Interno = '';
}
$this->db->select('empleados.Interno, empleados.Curp, empleados.Nombre, empleados.A_Paterno, empleados.A_Materno, cuentas.Clabe, cuentas.Banco, cuentas.Observaciones, cuentas.Status');
$this->db->from('empleados');
$this->db->join('cuentas',"cuentas.Interno = empleados.Interno AND cuentas.Status !='I'", 'Left');
$this->db->where('empleados.Interno', $Interno);
$q = $this->db->get();
$data = array();
$data['records'] = $q->result_array();
$this ->load -> view('main/indice', $data);
}

function update_Status()
{
$Interno= $this->input->post('Interno');
$data = array(
'Status' => $this->input->post('Inactivo')
);
if($this->consultas_M->update_Status($Interno, $data))
{
echo " update successful...";
}
else
{
echo "update not successful...";
}
}

使用函数search2,我显示两个表的结果(这可能是问题),然后我想将表cuentas的状态更改为“I”(非事件状态,默认情况下为“A”事件状态)。所以我只想更新状态列。但它没有任何作用。这是我的模型

function update_Status($Interno,$data)
{
$this->db->where('Interno', $Interno);
$this->db->update('cuentas', $data);
}

“Interno”是表中的 ID,也是显示该 ID 的输入名称。任何帮助将不胜感激

最佳答案

希望这对您有帮助:

你的 Controller 方法update_Status应该是这样的:

function update_Status() 
{
$Interno = $this->input->post('Interno');
$Status = $this->input->post('Inactivo');

$data['status'] = ! empty($Status) ? $Status : 'I';
if ( ! empty($Interno))
{
$updated = $this->consultas_M->update_Status($Interno, $data);
if($updated)
{
echo " update successful...";
}
else
{
echo "update not successful...";
}
}
else
{
echo "Interno not found ...";
}
}

此外,您应该根据表中的任何更改从 update_Status 方法返回 truefalse或不

注意:$this->db->affected_rows():在执行“写入”类型查询(插入、更新等)时显示受影响的行数.).

你的模型方法update_Status应该是这样的:

function update_Status($Interno,$data)
{
$this->db->where('Interno', $Interno);
$this->db->update('cuentas', $data);
if ( $this->db->affected_rows() > 0 )
{
return TRUE;
}
else
{
return FALSE;
}
/* OR you can simply return like this
return $this->db->update('cuentas', $data);
*/
}

关于php - 使用 codeigniter 更新表列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51032012/

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