Page 1 of 1

Loop Problem.

Posted: Fri Oct 17, 2008 7:51 am
by leathem
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


hello i have a loop, purpose is to compare and display results among other things, but i is only displaying one result, help!

Code: Select all

for($grpIndex = 0; $grpIndex < count($groupsArray); $grpIndex++)
  {
    echo "<".$groupsArray[$grpIndex].">";
 
    foreach ($projectsArrays[$grpIndex] as $tempZ) {  
     
      for($t = 0; $t < $numberOfFiles; $t++)
      {
      
        $thisFile = each($files);
        $file_name = $thisFile[0];
        
        if ($tempZ == $file_name) { 
       
          if( is_dir($dir_name."/".$file_name) )
          {
            # skip if directory name does not start with given filter prefix
            if( $filter && strpos($file_name, $filter) !== 0 )
            {
              continue;
            }
 
            # check last build result
            $logs = sortDir($dir_name."/".$file_name, "date", 1);
            $logCount = sizeOf($logs);
            $lastResult = "";
            $lastLabel = "-";
            $lastSuccessfulBuild = "";
            $lastAttempt = "";
            $logFile = "";
            $lastLog = "";
            $seenSuccess = false;
            $seenFailure = false;
 
            for($i = 0; $i < $logCount; $i++)
            {
              if( $seenSuccess === true && $seenFailure === true )
                break;
            
              $logEntry = each($logs);
              $logFile = $logEntry[0];
              $logTime = $logEntry[1];
 
              if( strpos($logFile, "log") !== 0 )
              {
                continue;
              }
              if( strpos($logFile, "L") && $seenSuccess === false )
              {
                if( $lastResult === "" )
                {
                  $lastResult = "SUCCESS";
                  $lastLog = $logFile;
                }
                $a = strpos($logFile, "L") + 1;
                $b = strpos($logFile, ".", $a);
                $lastLabel = substr($logFile, $a, $b - $a);
                $lastSuccessfulBuild = date($config["dateformat"], $logTime);
                if( $lastAttempt === "" )
                  $lastAttempt = $logTime;
                $seenSuccess = true;
              }
              else if( $seenFailure === false )
              {
                if( $lastResult === "" )
                {
                  $lastResult = "FAILURE";
                  $lastLog = $logFile;
                }
                if( $lastAttempt === "" )   
                  $lastAttempt = $logTime;
                $seenFailure = true;
              }
            }
            if( $lastResult === "" )
            {
               $lastResult = "WAITING";
            }
            $status = htmlentities(getBuildStatus($dir_name."/".$file_name."/".$config["buildstatus.filename"]));
          
            # strip away the .xml or .xml.gz postfix
            $a = strpos($lastLog, ".xml");
            if( $a !== false )
            {
              $lastLog = substr($lastLog, 0, $a);
            }
 
            if( $rss === true )
            {
              echo "<item>\n<title>${file_name}, ${lastResult}</title>\n";
              # echo "<description>${status}.</description>\n";
              echo "<description>${lastResult}</description>\n";
              echo "<pubDate>".($lastAttempt !== "" ? date(DATE_RFC2822, $lastAttempt) : "")."</pubDate>\n";
              echo "<link>".$config["url.prefix"]."?project=".
                   urlencode($file_name)."&log=".$lastLog."</link>\n";
              echo "</item>\n";
          
          # takes the divieded up string as individual  projects, move each project to $tempz then compares $tempz to the filename of each project, if there is a match the result is displayed!!
            } else  {
             
        
                
 
                  
                  echo "<project><name>".$file_name."</name><status>${status}</status>";
                  echo "<latestresult>".$lastResult."</latestresult>";
                  echo "<latestsuccess>".$lastSuccessfulBuild."</latestsuccess>";
                  echo "<latestattempt>".($lastAttempt !== "" ? date($config["dateformat"], $lastAttempt) : "")."</latestattempt>";
                  echo "<latestlabel>".$lastLabel."</latestlabel>";
                  echo "<latestlog>".$lastLog."</latestlog>";
                  echo "</project>"; 
                 
 
                  
                  
            if( $lastResult == "SUCCESS" )
              {
                $successCount++;
              }
            else if( $lastResult == "FAILURE" )
              {
                $failureCount++;
              }
              
            
           
           } 
            
          }//else
        }//if
      }//for 
    }//foreach
  echo "</".$groupsArray[$grpIndex].">";
}//for()grpindex

~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: Loop Problem.

Posted: Fri Oct 17, 2008 8:36 am
by aceconcepts
Try commenting out sections of you loops bit by bit so you can identify where the problem lies.

A lot of people are going to think there is far too much to look at.