$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表也不会生成任何输出。
e.g。对于2009年,只接受资产,而库存则没有。回显时,即使数据库中的Asset表中有数据,生成的表也是空的。
我已尝试从ISNULL,IFNULL,COALESCE中将sum()/ count()的值设置为0(我认为表生成的原因为空)但仍然无法生成数据。
为什么COALESCE功能不起作用,是因为使用了别名?例如COALESCE(sum(i.price),0))(如i.variable)
答案 0 :(得分:0)
更改PHP代码而不是db表,使用“”检查并设置数据,或者在回显之前将它们设置为空。