[英]codeigniter using Ignited-Datatables class stuck with joins
我在codeigniter中使用此庫
https://github.com/IgnitedDatatables/Ignited-Datatables/blob/master/application/libraries/Datatables.php
以及內部聯接實際存在問題,所有聯接都不對我有用。
$this->load->library('datatables');
$this->datatables
->select("id, date, customer_name, inv_total, total_tax, total_discount,
total, paid_by, cf1, cf2")
->from('sales')
->join('customers', 'customers.id=sales.customer_id', 'INNER')
->unset_column('id');
echo $this->datatables->generate();
cf1和cf2在客戶表中,我想檢索那些
由於您正在使用內部聯接,並且兩個表都包含名為id的字段,因此mysql對於字段歧義會返回錯誤。 因此,您應該通過tablename.feildname引用此類字段。
$this->datatables
->select("sales.id, date, customer_name, inv_total, total_tax, total_discount,
total, paid_by, cf1, cf2")
->from('sales')
->join('customers', 'customers.id=sales.customer_id', 'INNER')
->unset_column('sales.id');
echo $this->datatables->generate();
試試這些。
注意:您未在選擇查詢中包括客戶表名稱。
$this->load->library('datatables');
$this->datatables
->select("id, date, customer_name, inv_total, total_tax, total_discount, total, paid_by, customers.cf1, customers.cf2")
->from('sales')
->join('customers', 'customers.id=sales.customer_id', 'INNER')
->unset_column('id');
echo $this->datatables->generate();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.