使用codeigniter和mysql

时间:2018-05-19 08:57:36

标签: codeigniter

型号:

$this->db->where('payment_details.created_on >= ',$start_date);
    $this->db->where('payment_details.created_on <= ',$end_date);
    $this->db->where('receipt_details.created_on >= ',$start_date);
    $this->db->where('receipt_details.created_on <= ',$end_date);        
    $this->db->select('payment_details.id,payment_details.payment_no,payment_details.site_id,payment_details.vendor_id,payment_details.work,payment_details.description,payment_details.date,payment_details.amount,payment_details.tax_type,payment_details.tax,payment_details.subtotal,payment_details.grand_total,payment_details.created_on,receipt_details.id,receipt_details.receipt_no,receipt_details.site_id,receipt_details.vendor_id,receipt_details.work,receipt_details.description,receipt_details.date,receipt_details.amount,receipt_details.tax_type,receipt_details.tax,receipt_details.subtotal,receipt_details.grand_total,receipt_details.created_on,vendor.id,vendor.vname,site.id,site.sname');

$this->db->from('payment_details');        
$this->db->join('vendor','vendor.id=payment_details.vendor_id OR vendor.id=receipt_details.vendor_id','LEFT');
$this->db->join('site','site.id=payment_details.site_id OR site.id=receipt_details.site_id','LEFT');
return $this->db->get()->result();

enter image description here

我会尝试但运行此查询时出错 错误: 错误号码:1064

您的SQL语法有错误;检查与您的MariaDB服务器版本对应的手册,以便在{LEFT JOIN vendor ON vendor附近使用正确的语法。id = payment_detailsvendor_id或者vendor。“我在第2行

选择payment_detailsidpayment_detailspayment_nopayment_detailssite_idpayment_details。{{1} },vendor_idpayment_detailsworkpayment_detailsdescriptionpayment_detailsdatepayment_detailsamountpayment_detailstax_typepayment_detailstaxpayment_detailssubtotalpayment_details,{{ 1}}。grand_totalpayment_detailscreated_onreceipt_detailsidreceipt_detailsreceipt_no,{{1} }。receipt_detailssite_idreceipt_detailsvendor_idreceipt_detailsworkreceipt_detailsdescriptionreceipt_detailsdatereceipt_detailsamountreceipt_detailstax_typereceipt_detailstax。{{ 1}},receipt_detailssubtotalreceipt_detailsgrand_totalreceipt_detailscreated_onvendor。{{1} },idvendor LEFT JOIN vname ON siteid = sitesnamevendorvendor = idpayment_details LEFT JOIN vendor_id ON vendorid = receipt_detailsvendor_idsitesite = idpayment_details WHERE site_idsite&gt; ='2018-05-01'和{{1} }。id&lt; ='2018-05-31'和receipt_detailssite_id&gt; ='2018-05-01'和payment_details。{{1} }&lt; ='2018-05-31'

文件名:D:/xampp/htdocs/construct/system/database/DB_driver.php

行号:691 提前谢谢......

1 个答案:

答案 0 :(得分:0)

希望这会对您有所帮助(未经测试)

您的查询结构应该是这样的,只需提示您做必要的更改

$sql = 'SELECT payment_details.id,payment_details.payment_no,payment_details.site_id,payment_details.vendor_id,payment_details.work,payment_details.description,payment_details.date,payment_details.amount,payment_details.tax_type,payment_details.tax,payment_details.subtotal,payment_details.grand_total,payment_details.created_on,receipt_details.id,receipt_details.receipt_no,receipt_details.site_id,receipt_details.vendor_id,receipt_details.work,receipt_details.description,receipt_details.date,receipt_details.amount,receipt_details.tax_type,receipt_details.tax,receipt_details.subtotal,receipt_details.grand_total,receipt_details.created_on,vendor.id,vendor.vname,site.id,site.sname 
        FROM payment_details  
        JOIN (vendor, receipt_details, site)
        ON (vendor.id=payment_details.vendor_id OR vendor.id=receipt_details.vendor_id
        AND site.id=payment_details.site_id OR site.id=receipt_details.site_id)';
$query = $this->db->query($sql);
return $query->result();