不知道你的$oo和$o都是什么东西。
不过有几个建议:
1、把count($o)之类的东西拿到循环条件外面来,这样至少不是每次都去count一次。
2、慢的原因很可能是$x = new holiday($this->a);这个地方,估计new了不少个对象~~~看看怎么处理一下这个吧。
其他的地方我还没看出来~~

解决方案 »

  1.   


    <?
    require_once("function.php");
    class report
    {
    var $uid;
    var $pid;
    var $pStart;
    var $pEnd;
    var $a;
    var $quarter = array('First Quarter','Second Quarter','Third Quarter','Fourth Quarter');
    var $month = array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');

    function report($pid,$b)
    {
    //$this->uid = $uid;
    $this->pid = $pid;
    $this->a = $b;
    $p = $this->a->query("select * from PROJECT WHERE ID=".$pid);
    $this->pStart = $p[0]->PSTARTDATE!=""?$p[0]->PSTARTDATE:$p[0]->ADDTIME;
    $this->pEnd  = $p[0]->PENDDATE;
    }
    function projectName()
    {
    $sql = "select * from project where id=".$this->pid;
    $o = $this->a->query($sql);
    return $o[0]->PNAME;
    }
    function getPhase()
    {
    $sql = "select * from pr_phase where pid=".$this->pid;
    $o = $this->a->query($sql);
    return $o;
    }
    function getFeature()
    {
    $sql = "select * from feature where pid=".$this->pid." and active='1'";
    $o = $this->a->query($sql);
    return $o;
    }
    function getProActivity($prhid)//th_pr_phase 的ID
    {
    $sql = "select * from pro_activity where prhid=".$prhid;
    $o = $this->a->query($sql);
    return $o;
    }
    function getEmpActivity($praid)//th_pro_activity 的ID
    {
    $sql = "select * from emp_activity where praid=".$praid;
    $o = $this->a->query($sql);
    return $o;
    }
    function getHour($teamid,$eaid,$sDate,$eDate)//eaid 是th_emp_activity的ID。求两个日期间这个team在这个任务上所花的所有时间(h)
    {
    $sql  = "select sum(ctime) as ctime from time a,employee b where a.eid=b.id and b.teamid=".$teamid;
    $sql .= " and a.eaid='".$eaid."' and a.ctime>0 and a.cdate>=to_date('".$sDate."','yyyy-mm-dd')";
    $sql .= " and a.cdate<=to_date('".$eDate."','yyyy-mm-dd')" ;//and eid=".$this->uid
    $o = $this->a->query($sql);
    return $o[0]->CTIME;
    }
    /*
    function getTeamHour($eaid,$sDate,$eDate)//列出所有team在这个eaid下从$sDate开始到$eDate结束这段时间的所用的hour,并作为数组返回
    {
    $o = $this->a->query("select * from team");
    $hour = array();
    for($i=0;$i<count($o);$i++)
    {
    $hour[] = getHour($o[$i]->ID,$eaid,$sDate,$eDate);
    }
    return $hour;
    }
    */
    function getStartEnd($num)
    {
    switch($num)
    {
    case 4:
    $d = array(array('1-1','3-31'),array('4-1','6-30'),array('7-1','9-30'),array('10-1','12-31')); 
    break;
    case 12:
    $d = array(array('1-1','1-31'),array('2-1','2-19'),array('3-1','3-31'),array('4-1','4-30'),array('5-1','5-31'),array('6-1','6-30'),array('7-1','7-31'),array('8-1','8-31'),array('9-1','9-30'),array('10-1','10-31'),array('11-1','11-30'),array('12-1','12-31'));
    break;
    }
    return $d;
    }
    } class phaseReport extends report//统计每个phase下每个team的计划时间和实际用的时间
    {
    function getActivity($prhid)//求出单个phase下的所有的emp activity
    {
    $o = $this->getProActivity($prhid);
    $activity = array();
    for($i=0;$i<count($o);$i++)
    {
    $ooo = $this->getEmpActivity($o[$i]->ID);
    for($j=0;$j<count($ooo);$j++)
    $activity[] = $ooo[$j]->ID;
    }

    return $activity;
    }

    function getTeamHour($teamid,$prhid,$sDate,$eDate)//求出单个team在所有activity下这段日期内容所花的时间(h)
    {
    $o = $this->getActivity($prhid);
    $allHour = 0;
    for($i=0;$i<count($o);$i++)//[0]->ID
    $allHour += $this->getHour($teamid,$o[$i],$sDate,$eDate);
    return $allHour;
    }
    function getAllHour($num,$year)//显示所有team在这段时间内所用的时间
    {

    $day = $this->getStartEnd($num);
    $str = "<div align=\"center\" class=\"f18w\">Project ".$this->projectName()."</div><br>\r\n";
    $str .= '<table width="98%" border="0" cellspacing="1" cellpadding="0" bgcolor="#66A9F0" align="center">
       <tr bgcolor="#F3FFFF"><td align="center" height="30">&nbsp;</td><td align="center">Team</td><td>&nbsp;</td>'."\r\n";
    $title = $num ==4?$this->quarter:$this->month;
       for($i=0;$i<$num;$i++)
    $str .= '<td align="center">'.$title[$i].'</td>'."\r\n";
    $str .= "</tr>\r\n";

    $o = $this->a->query("select * from team");
    $oo = $this->getPhase();
    $time1 = time();

    for($j=0;$j<count($oo);$j++)
    {
    for($i=0;$i<count($o);$i++)
    {//显示Plan

    $str .= '<tr bgcolor="#F3FFFF">'."\r\n";

    $str .= "<td align=\"center\" height=\"25\">".($i==0?getPhaseFromId($oo[$j]->PHID):"")."</td>\r\n";
    $str .= "<td align=\"center\">".$o[$i]->DESCRIPTIONS."</td>\r\n";
    $str .= "<td align=\"center\">Plan</td>\r\n";

    for($h=0;$h<$num;$h++)
    {
    $x = new holiday($this->a);
    $str .= "<td align=\"center\">".$x->getTeamHour($o[$i]->ID,$year.'-'.$day[$h][0],$year.'-'.$day[$h][1])."</td>\r\n";
    }

    $str .= "</tr>\r\n";
    //显示Actual
    $str .= '<tr bgcolor="#F3FFFF">'."\r\n";

    $str .= "<td height=\"25\">&nbsp;</td>\r\n";
    $str .= "<td>&nbsp;</td>";
    $str .= "<td align=\"center\">Actual</td>\r\n";

    for($h=0;$h<$num;$h++) 
    $str .= "<td align=\"center\">".$this->getTeamHour($o[$i]->ID,$oo[$j]->ID,$year.'-'.$day[$h][0],$year.'-'.$day[$h][1])."</td>\r\n";

    $str .= "</tr>\r\n";
    //显示Delta
    $str .= '<tr bgcolor="#F3FFFF">'."\r\n";

    $str .= "<td height=\"25\">&nbsp;</td>\r\n";
    $str .= "<td>&nbsp;</td>";
    $str .= "<td align=\"center\">Delta</td>\r\n";

    for($h=0;$h<$num;$h++)
    $str .= "<td align=\"center\"></td>\r\n";

    $str .= "</tr>\r\n";

    }

    }

    $time2 = time();
    echo ($time2-$time1)."<br>";
    $str .= "</table>\r\n<br>";

    return $str;
    }
    }
    ?>
      

  2.   

    数据太少,无法估计
    $oo,$o,holiday这些是什么大量建立对象:
    $x = new holiday($this->a);
      

  3.   

    楼上面说的有道理,如果你new的那个对象是一样的话,就不要放在循环里了,要不你说在for循环后面unset那个new
      

  4.   


    <?
    //require_once('function.php');
    class holiday
    {
    var $a;

    function holiday($b)
    {
    $this->a = $b;
    }

    function getDay($table,$sDate,$eDate)//求出两个日期间的工作日或假期
    {
    $str  = $sDate!=""?" cdate >= to_date('".$sDate."','yyyy-mm-dd') and ":"";
    $str .= $eDate!=""?" cdate <= to_date('".$eDate."','yyyy-mm-dd') and ":"";
    $str = substr($str,0,-4);
    $sqlStr = $str !=""?$sqlStr = " where ".$str:"";

    $sql = "select * from mcd_dba.$table ".$sqlStr;
    $o =  $this->a->query($sql);
    $arr = array();
    for($i=0;$i<count($o);$i++)
    $arr[$i] = $o[$i]->CDATE;
    return $arr;
    }
    function getUsersHoliday($eid,$sDate,$eDate)//得到用户的假期
    {
    $str  = $sDate!=""?" datef>= to_date('".$sDate."','yyyy-mm-dd') and ":"";
    $str .= $eDate!=""?" datet<= to_date('".$eDate."','yyyy-mm-dd') and ":"";
    $str = substr($str,0,-4);
    $sqlStr = $str !=""?$sqlStr = " and ".$str:"";

    $sql = "select datef,datet from emp_holiday where eid=".$eid." ".$sqlStr;
    $o = $this->a->query($sql);
    $holiday = array();
    for($i=0;$i<count($o);$i++)
    {
    $j = 0;
    while(compareTime($o[$i]->DATET,addDays($o[$i]->DATEF,$j)))
    {
    $holiday[] = addDays($o[$i]->DATEF,$j);
    $j++;
    }
    }
    return $holiday;
    }
    function getWeekend($sDate,$eDate)//找出这段时间的周末
    {
    $j = 0;
    $weekend = array();
    while(compareTime($eDate,addDays($sDate,$j)))
    {
    $b = explode("-",addDays($sDate,$j));
    $d = date('w',mktime(0,0,0,$b[1],$b[2],$b[0]));
    if($d==0||$d==6)
    $weekend[] = addDays($sDate,$j);
    $j++;
    }
    return $weekend;
    }
    function getUserHoliday($eid,$sDate,$eDate)//求出某段时间所有的假期,以数组形式返回
    {
    $pHoliday = $this->getDay("th_holiday",$sDate,$eDate);//所有法定假期,09年,共11天,
    $weekend = $this->getWeekend($sDate,$eDate);//这段时间的所有周末
    $mHoliday = $this->getUsersHoliday($eid,$sDate,$eDate);//这段时间的私人假期
    $workDay = $this->getDay("th_workingday",$sDate,$eDate);//这段时间的本来是周末,但需要工作的日期

    $holiday = array_merge($pHoliday,$weekend,$mHoliday);
    $holiday = array_diff($holiday,$workDay);
    $holiday = array_unique($holiday);
    return $holiday;
    }
    function getTeamUser($teamid)
    {
    $sql = "select * from employee where teamid=".$teamid;
    $o = $this->a->query($sql);
    return $o;
    }
    function getTeamHour($teamid,$sDate,$eDate)
    {
    $allDay = (strtotime($eDate)-strtotime($sDate))/(60*60*24)+1;
    $o = $this->getTeamUser($teamid);

    $allDays = 0;
    for($i=0;$i<count($o);$i++)
    {
    $allDays += $allDay-count($this->getUserHoliday($o[$i]->ID,$sDate,$eDate));
    }
    return $allDays*8.5;
    }
    }
    /*
    $b = new db;
    $a = new holiday($b);
    $x = $a->getTeamHour('2','2009-2-8','2009-2-11');
    echo $x;
    */
    ?>
      

  5.   

    用过new 对象,记得要unset();
      

  6.   

    我输出了下时间,主要就是两个for循环那里用的时间太多。其他地方基本上不到1s,但是两个for那里用了15、6秒。有人说是输出的字符串太大了,不知道是不是这个原因。。
      

  7.   

    你应该将计算部份及输出部份分离
    先计算所有结果~存进array
    再用这个array 拼输出的 html你现在计算部份跟输出的html堆在一起
    很难看明白
      

  8.   

    可能是吧,不要欠入HTML代码输出了!
      

  9.   

    这是在我第一次说的第二个for里开始放个time(),结尾放个time().相减得出来的,就是for循环里运行的时间。谢谢各位了。1
    1
    1
    1
    1
    1
    0
    1
    0
    0
    1
    1
    0
    0
    1
    0
    0
    0
    1
    0
    1
    0
    1
    0
    0
    1
    0
    0
    1
    1
    0
    0
    1
    0
      

  10.   

    程序中:
    for($i=0;$i<count($o);$i++)
    改成:
    $count = count($o);
    for($i=0;$i<$count;$i++)for($i=0;$i<count($o);$i++)
                {
                    $j = 0;
                    while(compareTime($o[$i]->DATET,addDays($o[$i]->DATEF,$j)))
                    {
                        $holiday[] = addDays($o[$i]->DATEF,$j);
                        $j++;
                    }
                }
    这一块看看可不可以简化一下,比较放在sql语句中行不?