简体   繁体   English

如何加入表Codeigniter

[英]How to get to join table Codeigniter

My model: 我的模特:

        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);
}

My controler: 我的控制者:

    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);
}

I have problem to delete data from join table, get this message when I try delete: 我无法从联接表中删除数据,尝试删除时会收到以下消息:

A Database Error Occurred 发生数据库错误

Error Number: 1146 错误号:1146

Table 'ci.object' doesn't exist 表'ci.object'不存在

DELETE FROM `Object` WHERE `m`.`id` = '13' 从`Object`的`m`.`id` ='13'删除

Filename: C:\\xampp\\htdocs\\ci\\system\\database\\DB_driver.php 文件名:C:\\ xampp \\ htdocs \\ ci \\ system \\ database \\ DB_driver.php

Line Number: 330 行号:330

So probably theres a problem with table in function delete. 因此,函数删除中的表可能存在问题。 I try on different ways to get to this table and I don't know how to solve this. 我尝试使用各种方法到达此表,但我不知道该如何解决。 Any clue? 有什么线索吗?

You're passing a CI Object into $this->db->delete() as $this->users_m->category() returns a DB result array of object(s). 您正在将CI对象传递到$this->db->delete()因为$this->users_m->category()返回对象的DB结果数组。

CI Delete works by passing in the table name, in your case it looks like it will be CI Delete可以通过输入表名来工作,在您的情况下,它看起来像是

 public function delete($where) {
     $this->db->where('meeting m', $where);
     $this->db->delete('meeting');
 }

I can't work out why you have extra values in there 我不知道为什么你在那里有额外的价值

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

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