php - php在phpmyadmin中生成查询显示错误
问题描述
select student.studentID, invoice.invoiceID, student.name,
MONTHNAME(STR_TO_DATE(invoice.month, '%m')) as Month, invoice.tuitionfee as 'Total Amount', payment.tuitionpaid
from invoice
join student
left join payment
on invoice.studentID = student.studentID and invoice.invoiceID = payment.invoiceID
where invoice.`create_date` > DATE_SUB(now(), INTERVAL 6 MONTH) and student.studentID = '28' group by invoice.month
上面的查询可以运行并给我所需的结果,但仅限于 phpmyadmin
问题是,当我将此查询放入我的 php 代码(codeigniter)并且模型生成的查询未运行时,我不知道该怎么做,请帮助我
PHP 代码
public function get_month_wise_dues($id){
$this->db->select("student.studentID,
invoice.invoiceID, student.name,
MONTHNAME(STR_TO_DATE(invoice.month, '%m')) as Month,
invoice.tuitionfee as 'Total Amount', payment.tuitionpaid");
$this->db->from('invoice');
$this->db->join('student','invoice.studentID = student.studentID');
$this->db->join('payment','invoice.invoiceID = payment.invoiceID','LEFT');
$this->db->where('invoice.`create_date` > DATE_SUB(now(), INTERVAL 6 MONTH) and student.studentID=', $id);
$this->db->group_by('invoice.month');
$this->db->order_by('invoice.month', 'asc');
$query = $this->db->get();
// echo $this->db->last_query();
// exit;
return $query->result();}
这是 php 生成的查询
SELECT `student`.`studentID`, `invoice`.`invoiceID`, `student`.`name`, MONTHNAME(STR_TO_DATE(invoice.month, `'%m'))` as Month, `invoice`.`tuitionfee` as 'Total Amount', `payment`.`tuitionpaid`
FROM (`invoice`)
JOIN `student` ON `invoice`.`studentID` = `student`.`studentID`
LEFT JOIN `payment` ON `invoice`.`invoiceID` = `payment`.`invoiceID`
WHERE `invoice`.`create_date` > DATE_SUB(now(), INTERVAL 6 MONTH) and
student.studentID= '28'
GROUP BY `invoice`.`month`
ORDER BY `invoice`.`month` asc
当我运行 php 生成的查询时,它没有像提到的第一个查询那样给我所需的结果
错误如下
1064 - 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在 'FROM (
invoice
) JOINstudent
ON附近使用的正确语法invoice
。studentID
=student
。studentID
' 在第 2 行
解决方案
推荐阅读
- go - 从存储解组函数输出的变量中删除所有非字母数字字符
- eve - EVE REST API - 从端点获取随机项目
- c++ - XSD 联合上的 QXmlSchemaValidator 段错误
- windows - Git Extensions 无法获取,git bash 工作
- typescript - TypeScript 3.5 和 3.6 之间的泛型参数推断不匹配
- c# - 使用带有回调的 net.tcp 绑定的 WCF 超时问题
- python - ImportError:无法导入名称“LatentDirichletAllocation”
- r - 在 r 中使用 nc 数据写入栅格
- html - 有没有办法让下拉菜单在网页中嵌入图像
- arrays - 门禁应用(过滤数据MongoDB)