简体   繁体   中英

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

Table 'ci.object' doesn't exist

DELETE FROM `Object` WHERE `m`.`id` = '13'

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

Line Number: 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 Delete works by passing in the table name, in your case it looks like it will be

 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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