我似乎无法正常工作,这让我发疯。我正在使用在github]中找到的CodeIgniter的Ignited Datatables库
我有下面的方法可以从连接到另一个表的表中获取记录:
public function get_templates_ajax() { $this->datatables->select('tem.template_id, tem.name, tem.vat, COUNT(itm.template_id) AS total_items'); $this->datatables->from('templates tem'); $this->datatables->join('items itm', 'tem.template_id = itm.template_id', 'left'); $this->datatables->where('tem.user_id', $this->session->user_id); $this->datatables->group_by('tem.template_id'); $this->datatables->add_column('actions', '<a href="javascript:void(0);" class="edit_record btn btn-info" data-id="$1" data-name="$2" data-vat="$3">Edit</a><a href="javascript:void(0);" class="delete_record btn btn-danger" data-id="$1">Delete</a>', 'tem.template_id, tem.name, tem.vat'); return $this->datatables->generate(); }
[是,我在两个表中都有一个名为
user_id
的字段,但是我没有选择该列,但是,出现此错误:重复的列名'user_id'。
我指定了要选择的列,如下所示:
$this->datatables->select('tem.template_id, tem.name, tem.vat, COUNT(itm.template_id) AS total_items');
我知道是否要选择user_id列,我将使用别名,但未选择它。
正在执行$this->db->last_query();
转储此SQL:
SELECT COUNT(*) FROM (SELECT * FROM `templates` `tem` LEFT JOIN `items` `itm` ON `tem`.`template_id` = `itm`.`template_id` WHERE `tem`.`user_id` = '1' GROUP BY `tem`.`template_id`) SqueryAux
因此似乎在从两个表中选择所有列时,select方法被忽略了。我可能做错了什么?
我似乎无法正常工作,这让我发疯。我正在使用我在github上发现的CodeIgniter的Ignited Datatables库,我有以下方法可从连接到...的表中获取记录...
经过大量挖掘,我通过对库进行一些调整解决了该问题。