【发布时间】:2012-08-23 16:36:48
【问题描述】:
$pdf->Table('select @N:=@N+1 AS no,
A.department as "DEPARTMENT",
A.no as "ASSET NUMBER" ,
A.total as "ASSET TOTAL PRICE" ,
B.no as "INVENTORY NUMBER" ,
B.total as "INVENTORY TOTAL PRICE"
from
(select h.department , coalesce(count(h.id),0) as no,coalesce(sum(h.price),0) as total
from asset h
where h.department = "'.$department.'"
and year(h.date_accepted) = '.$year.'
GROUP BY year(h.date_accepted)) as A ,
(select coalesce(count(i.id),0) as no,coalesce(sum(i.price),0) as total
from inventory i
where i.department = "'.$department.'"
and year(i.date_accepted) = '.$year.'
GROUP BY year(i.date_accepted)) as B ',$prop);
我正在制作一个 PDF 文件,该文件将生成从 SQL 读取的表。 问题是当数据库中的任何行为空时,即使其他表中有数据,PDF 表也不会生成任何输出。
例如2009 年只接受资产,而没有库存。回显时,即使数据库的资产表中有数据,生成的表也是空的。
我尝试了从 ISNULL、IFNULL、COALESCE 到将 sum()/count() 的值设置为 0(我认为生成的表为空的原因)的所有方法,但仍然无法生成数据。
为什么 COALESCE 函数不起作用,是因为使用了别名吗?例如 COALESCE(sum(i.price),0))(如 i.variable)
【问题讨论】:
-
不管这里发生了什么,看起来至少存在三个严重的 SQL 注入错误。我真的希望这些值被转义。
标签: mysql sql pdf-generation fpdf coalesce