我有这个帐单表,我可以根据报告要求从中获取记录。
我得到的数组是这样的:
Array(
[0] => stdClass Object
(
[bid] => 3
[uid] => 2
[total_inc] => 100
[total_exp] => 55
[mon] => 1
[year] => 2012
[mstdatereg] => 2012-03-14
)
[1] => stdClass Object
(
[bid] => 2
[uid] => 3
[total_inc] => 85
[total_exp] => 45
[mon] => 1
[year] => 2012
[mstdatereg] => 2012-03-14
)
[2] => stdClass Object
(
[bid] => 1
[uid] => 8
[total_inc] => 130
[total_exp] => 75
[mon] => 1
[year] => 2012
[mstdatereg] => 2012-03-14
)
[3] => stdClass Object
(
[bid] => 5
[uid] => 25
[total_inc] => 130
[total_exp] => 65
[mon] => 2
[year] => 2012
[mstdatereg] => 2012-03-14
)
[4] => stdClass Object
(
[bid] => 4
[uid] => 27
[total_inc] => 75
[total_exp] => 50
[mon] => 2
[year] => 2012
[mstdatereg] => 2012-03-14
)
[5] => stdClass Object
(
[bid] => 10
[uid] => 3
[total_inc] => 180
[total_exp] => 100
[mon] => 3
[year] => 2012
[mstdatereg] => 2012-04-05
)
[6] => stdClass Object
(
[bid] => 6
[uid] => 12
[total_inc] => 60
[total_exp] => 35
[mon] => 3
[year] => 2012
[mstdatereg] => 2012-03-14
)
[7] => stdClass Object
(
[bid] => 7
[uid] => 22
[total_inc] => 160
[total_exp] => 90
[mon] => 3
[year] => 2012
[mstdatereg] => 2012-03-14
)
[8] => stdClass Object
(
[bid] => 9
[uid] => 3
[total_inc] => 115
[total_exp] => 70
[mon] => 4
[year] => 2012
[mstdatereg] => 2012-03-16
)
)
我通过循环所做的结果是这样的:
January, 2012
==========
Income Expense
2 100 55
3 85 45
8 130 75
---------------------------------
Total 315 175
February, 2012
===========
Income Expense
25 130 65
27 75 50
---------------------------------
Total 205 115
March, 2012
Income Expense
3 180 100
12 60 35
22 160 90
---------------------------------
Total 400 225
April, 2012
Income Expense
3 115 70
---------------------------------
Total 115 70
Net Total Income: 1035
Net Total Expense: 585code here
但是我想要的是
Sr.No Member 1, 2012 2, 2012 3, 2012 4, 2012 Total
Inc|Exp Inc|Exp Inc|Exp Inc|Exp Inc|Exp
=======================================================================
1 2 100|55 100|55
2 3 85|45 180|100 115|70 380|215
3 8 130|75 130|75
4 25 130|65 130|65
5 27 75|50 75|50
6 12 60|35 60|35
7 22 160|90 160|90
=======================================================================
Total 315|175 205|115 400|225 115|70 1035|585
在发布之前,我搜索了这样的问题,这就是我发现的:Building a "crosstab" or "pivot" table from an array in php
我试图让它按照我的要求工作,但 cud 不这样做。
已经尝试了很多天了。任何帮助将不胜感激。