0
$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)

4

1 回答 1

0

更改您的PHP代码而不是db表,使用“”或任何内容自行检查和设置数据,如果这些在回显之前为空。

于 2012-08-29T06:44:18.863 回答