我正在尝试使用php和MySQL创建一个Web应用程序,它可以根据存储在数据库中的数据绘制一个人的估计工作量
$luna_start = date('n', strtotime($row_task['data_i']));
$luna_end = date('n', strtotime($row_task['data_s']));
$luna_curenta=$luna_start;
$ultimazi_luna_curenta= cal_days_in_month(CAL_GREGORIAN, $luna_curenta,"2012");
while ($luna_curenta<=$luna_end){
//construieste vectorul
for ($i = 1; $i <= $ultimazi_luna_curenta; $i++) {
$data_curenta= date("Y-m-d", mktime(0, 0, 0, $luna_curenta, $i, 2012));
if (($data_curenta>=$row_task['data_i'])&&($data_curenta<=$row_task['data_s'])){
$efort_a['a'.$row_task['task_id']][$data_curenta]=$efort_mediu;
}
}
$luna_curenta++;
}
获取数组的所有麻烦,以便我可以绘图。数组$ efort_a看起来像这样:
Array(
[a19] => Array(
[2012-09-20] => 2.84
[2012-09-21] => 2.84
.......
[2012-10-21] => 2.84
[2012-10-22] => 2.84
)
[a22] => Array
(
[2012-10-01] => 0.1
[2012-10-02] => 0.1
.....
[2012-11-05] => 0.1
[2012-11-06] => 0.1
[2012-11-07] => 0.1
......
[2012-11-25] => 0.1
......
[2012-11-30] => 0.1
)
[a16] => Array
(
[2012-10-08] => 4
[2012-10-09] => 4
[2012-10-10] => 4
[2012-10-11] => 4
......
[2012-10-18] => 4
[2012-10-19] => 4
)
)
我正在做更多的数组处理。
extract($efort_a);
$graf_data= array_add($a19,$a22,$a16);
$data = new GoogleChartData($graf_data);
$chart->addData($data);
所有这些代码的问题在于它不是动态代码。数组a19,a22,a16是静态命名的,在这种特殊情况下,用户只有3个任务(任务ID 19,22和16)......但是如果用户有多个任务怎么办?
ps:基于键添加数组的功能是:
function array_add($a1, $a2) {
// adds the values at identical keys together
$aRes = $a1;
foreach (array_slice(func_get_args(), 1) as $aRay) {
foreach (array_intersect_key($aRay, $aRes) as $key => $val) $aRes[$key] += $val;
$aRes += $aRay;
}
return $aRes;
}
=========================================第2天==== ===================
经过一番思考之后,我想再试一次......所以为了动态地命名数组的关键字,我需要知道在哪里停止增量所以:$sql_nrtask='SELECT *, COUNT(user) AS nr_task
FROM task
WHERE user="ASD"
ORDER BY data_i ASC
';
$query_nrtask= mysql_query($sql_nrtask) or die ('rrr');
while ($row_nrtask= mysql_fetch_array($query_nrtask)) {
$nr_task=$row_nrtask['nr_task']; // no we know how many sub-arrays we'll have
}
for ($j++;$j<=$nr_task;$j++){
while ($luna_curenta<=$luna_end){
//construieste vectorul
for ($i = 1; $i <= $ultimazi_luna_curenta; $i++) {
$data_curenta= date("Y-m-d", mktime(0, 0, 0, $luna_curenta, $i, 2012));
if (($data_curenta>=$row_task['data_i'])&&($data_curenta<=$row_task['data_s'])){
$efort_a['$a'.$j][$data_curenta]=$efort_mediu;
}
}
$luna_curenta++;
}
}
问题是知道我不知道将$ efort_a中的数组合并为2个条件: