我在连接 3 个表时遇到困难。
我有下表(列)
apk_inv_item ( item_id
)
apk_inv_category ( category_id
)
apk_inv_item_category_defination ( item_id
, category_id
)
我想从项目到类别映射表中获取项目的类别 ID。
这是我到目前为止尝试过的。.但它
select("apk_inv_item.*, apk_inv_category.inv_category_id")
->join("apk_inv_category", "apk_inv_item_category_defination.inv_category_id
= apk_inv_category.inv_category_id")
->find_all();
但我明白Call to a member function num_rows()
这意味着查询不正确。(请注意,我已经尝试了简单的 2 表与另一个表的连接进行测试,它可以工作,这意味着我的 MySQL 连接或 PHP 代码没有问题。构建该查询的问题)
试试这个..
$this->db->select('*');
$this->db->from('apk_inv_item');
$this->db->join('apk_inv_category', 'apk_inv_category.category_id= apk_inv_item_category_defination.category_id');
$this->db->join('apk_inv_item_category_defination', 'apk_inv_item_category_defination.item_id = apk_inv_item.item_id');
$count = $this->db->count_all_results();
return $count;
希望它有帮助。