【发布时间】:2014-12-22 17:43:56
【问题描述】:
我想从‘table1’中删除那些 (user_id = 5) 的行,但我应该检查那些帖子’(title = table2 中的 title1)。我使用 Codeigniter,但在尝试删除时出现此错误:'不允许删除,除非它们包含“where”或“like”子句。'请您帮我检查一下我的代码有什么问题。
table1:
table2:
public function delete($title, $user_id){
$this->db->select('table1.*');
$this->db->from('table1','table2');
$this->db->where('table1.user_id', $user_id);
$this->db->where('table2.title', $title);
$this->db->join('table2','table1.post_id=table2.post_id');
$query = $this->db->get();
if ($query && $query->num_rows() > 0) {
$this->db->delete('table1.*');
$this->db->from('table1','table2');
$this->db->where('table1.user_id', $user_id);
$this->db->where('table2.title', $title);
$this->db->join('table2','table1.post_id=table2.post_id');
return true;
}
else {
return false;
}
}
【问题讨论】:
标签: php mysql codeigniter join