简体   繁体   English

使用Codeigniter更新DB表中的字段状态

[英]updating a field status in DB table using Codeigniter

I want to update the 'not yet' status to 'already' 我想将“尚未”状态更新为“已经”

Have error 有错误

A Database Error Occurred
Error Number: 1054
Unknown column 'sudah' in 'field list'
UPDATE `tb_peserta` SET `sudah` = '' WHERE `no_pendaftaran` = '13'
Filename: C:/xampp/htdocs/codeigniter/system/database/DB_driver.php
Line Number: 691

My Controller 我的控制器

function status_verifikasi($no_pendaftaran){
    $where = array('no_pendaftaran' => $no_pendaftaran);
    $this->M_pendaftar->status_verifikasi($where,'tb_peserta');
    redirect('admin/Ca_pendaftar');}

My Model 我的模特

function status_verifikasi($where,$tb_peserta){
    if ($status_verifikasi ='belum') {
       $this->db->set('sudah');
   } else{
       $this->db->set('belum');
   }
   $this->db->where($where);
   $this->db->update($tb_peserta);}

My View 我的观点

<?=anchor('admin/Ca_pendaftar/status_verifikasi/'.$tb_peserta->no_pendaftaran,
              'Konfirmasi', ['class'=>'btn btn-success btn-sm' , 'onclick'=>"return confirm('Ubah status pendaftar ?');"])?>

Codeigniter Set syntax should be Codeigniter Set语法应该是

$this->db->set('column_name','value');

Note : Equal = is assignment operator . 注意:Equal =是赋值运算符。 To compare you need to use == comparison operator 要比较你需要使用==比较运算符

if ($status_verifikasi == 'belum') { .. }

Update1: UPDATE1:

you need to check the previous value using select query like this then you need to update the status based on previous value . 您需要使用这样的选择查询检查以前的值,然后您需要根据以前的值更新状态。

function status_verifikasi($where,$tb_peserta){

     $this->db->select('status_verifikasi');
     $this->db->from($tb_peserta);
     $this->db->where($where);
     $result = $this->db->get()->result();

    if($result && $result[0]->status_verifikasi =='belum')
    {
       $this->db->set('status_verifikasi','sudah');
    } else{
       $this->db->set('status_verifikasi','belum');
    }

    $this->db->where($where);
    $this->db->update($tb_peserta);
}

$this->db->set('sudah');

should be something like 应该是这样的

$this->db->set('sudah', 'value');

There is one more issue 还有一个问题

// you have used assignment operator instead of comparison operator //您使用了赋值运算符而不是比较运算符

if ($status_verifikasi ='belum') {

should be 应该

if ($status_verifikasi == 'belum') {

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM