我正在用 php zend 框架和 sql server 2008 开发一个网站。
我需要创建一个多维数组,以这种格式按年和月存储数据:
Array(
[2012] => Array(
[11] => Array(
// data
)
[12] => Array(
// data
)
)
[2013] => Array(
[01] => Array(
// data
)
[02] => Array(
// data
)
[03] => Array(
// data
)
[04] => Array(
// data
)
)
)
但是我的结果数组中有重复项。意味着我也在 2013 年获得 2012 年的数据。我的代码如下:
// Database functions to get data
function select_cldata($month,$year)
{
global $db;
$select = "select ClientId,ClientName,Email,Request,'Order Placed' as info from tbl_clrequest where MONTH(CreatedDate) = ".$month." and YEAR(CreatedDate) = ".$year;
return $db->fetchAll($select);
}
function select_itemsdata($month,$year)
{
global $db;
$select = "select ItemId,ItemName,Desc,price,'Items delivered' as info1 from tbl_items where MONTH(ItemDate) = ".$month." and YEAR(ItemDate) = ".$year;
return $db->fetchAll($select);
}
// PHP Code
$test = new dbase();
$months = "2012-11,2012-12,2013-01,2013-02,2013-03,2013-04";
$mon_num = explode(",",$months);
$res = array();
$result = array();
foreach($mon_num as $mn)
{
$mm = explode("-",$mn);
$year = $mm[0];
$month = $mm[1];
$cl_data = $test->select_cldata($month,$year);
$dl_data = $test->select_itemsdata($month,$year);
$res[$month] = array_merge($clients,$sr,$events,$ses,$docs,$event_change,$devents);
$result[$year] = $res;
}
echo "<pre>";
print_r($result);die;
谁能帮帮我?