Php 如何加入表Codeigniter
我的模型:Php 如何加入表Codeigniter,php,mysql,codeigniter,join,Php,Mysql,Codeigniter,Join,我的模型: public function category($column, $value) { $this->db->select('c.cat2, c.category, m.id, m.date, m.when_date, m.when_time, m.where_m, m.age1, m.age2, m.opis, m.rozpoznamy'); $this->db->from('category c'); $this-&
public function category($column, $value)
{
$this->db->select('c.cat2, c.category, m.id, m.date, m.when_date, m.when_time, m.where_m, m.age1, m.age2, m.opis, m.rozpoznamy');
$this->db->from('category c');
$this->db->where($column, $value);
$this->db->join('meeting m', 'm.id_cat = c.id');
$result = $this->db->get();
return $result->result();
}
public function delete($where, $column, $value)
{
$this->db->delete($this->users_m->category($column, $value), $where);
}
我的控制者:
public function delete()
{
$cat = $this->uri->segment(3);
$value = $this->uri->segment(4);
$column = 'm.id';
$where = array('m.id' => $value);
$this->users_m->delete($where, $column, $value);
redirect('main/category/' . $cat);
}
我无法从联接表中删除数据,尝试删除时收到以下消息:
发生数据库错误
错误号码:1146
表“ci.object”不存在
从`Object`中删除,其中`m`.`id`=“13”
文件名:C:\xampp\htdocs\ci\system\database\DB\u driver.php
电话号码:330
所以函数delete中的表可能有问题。我尝试了不同的方法来达到这张桌子,但我不知道如何解决这个问题。有线索吗 将CI对象传递到$this->db->delete中,因为$this->users\m->category返回对象的db结果数组 CI Delete通过传入表名来工作,在您的情况下,它看起来将是
public function delete($where) {
$this->db->where('meeting m', $where);
$this->db->delete('meeting');
}
我不明白为什么在那里有额外的值错误说明所有表'ci.object'都不存在。请确保该表存在!!!我知道,但我认为问题在于:$this->db->delete$this->users\u m->category$column,$value,$where;这里的specyfic:$this->users\m->category$column,$value我正试图从这个模型中的其他functioncategory获取联接表。也许我已经放弃了这个表,直到问题出现:发生了数据库错误错误号:1064您的SQL语法有错误;检查与您的MySQL服务器版本对应的手册,以了解在第1行使用near'm WHERE m.id='13的正确语法从会议中删除m WHERE m.id='13'文件名:C:\xampp\htdocs\ci\system\database\DB\u driver.php行号:330,但更改为:public function DELETE$WHERE{$this->DB->DELETE'meeting m',$WHERE;}好的,把它改成:公共函数delete$where{$this->db->delete'meeting',$where;}和controller:$where=array'id'=>value;现在可以了,谢谢;