Re: Infinite Loop Issue

From: Date: Thu, 06 Nov 2008 22:56:46 +0000
Subject: Re: Infinite Loop Issue
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-283041@lists.php.net to get a copy of this message
Kyle Terry wrote:
I believe I'm doing everything right here. It just seems like it doesn't end. The browser just keeps trying to load the page forever... function displayAll(){
    global $db;
    $sql = "SELECT release_id, description, date(release_date) date, issues,
priority FROM release_data";
how many rows does this return?
    while($all->fetch()){
        $i = 0;
        $iss_link = explode(', ', $issues);
        foreach($iss_link as $a){
          $row2[$i] = "<a href=\"http://mantisus/view.php?id=$a\"
target=\"_blank\">".$a.'</a>';
          $i++;
        }
<snip> You have a loop inside a loop. What makes it worse is that the loop is growing with every iteration. If there are 100 rows, then at the end, there are 100 entries in the $issues array. To get to that point, you are doing a loop of size "X" where "X" = the row number being processed. ie row "2" is doing a foreach over 2 entries. row 15 is doing a foreach over 15 entries. row 90 is doing a foreach over 90 entries. -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.general (#283041) next »