【问题标题】:Selecting from table where value update other table value Codeigniter problem从值更新其他表值Codeigniter问题的表中选择
【发布时间】:2018-10-07 11:07:25
【问题描述】:

我的 CodeIgniter 网站有一些问题我正在尝试从表“订单”列“自定义”中选择一个值,如果此电子邮件地址与当前登录的用户的电子邮件地址匹配,则需要设置 @987654321 @在'users' table to 1。但我收到一条错误消息。我的编码经验很少,这就是我想出的:

public function hasDonated($email){
$this->db->from('orders');
    $this->db->where('custom', $email);
    $this->db->update('users', array('donater' => '1'));
    return;
}

这是我得到的错误,它试图在users 表中选择'custom',但需要从“订单”表中选择我做错了什么?

Unknown column 'custom' in 'where clause'

UPDATE `users` SET `donater` = '1' WHERE `custom` = 'testing@test.com'

【问题讨论】:

  • 请检查customorders 表中是否可用。
  • 是的,但我认为脚本正在用户表中寻找自定义,所以我不知道我做错了什么
  • 你能在这里列出users表的字段吗?

标签: php mysql sql codeigniter


【解决方案1】:

你可以这样做:

public function hasDonated($email){
$resp = $this->db->select('custom')->from('orders')->where('custom',$email)->get();
    if( $resp->num_rows() > 0 ) {   
    $this->db->set('donater', 1);
    $this->db->where('email', $email);
    $this->db->update('users');
  }
  return;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-31
    • 1970-01-01
    • 1970-01-01
    • 2012-06-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多