function dying right in the middle of a for() loop, while simply doing a bunch of echo statements

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lawrence

    #1

    function dying right in the middle of a for() loop, while simply doing a bunch of echo statements

    Right now, over at www.monkeyclaus.org, the following script is
    getting to the 9th run through and dying after the line:

    echo "...";


    You'll admit that is a strange place to die. I've hit refresh several
    times and it keeps happening. When I view page source, the last thing
    that shows up is the "...". The date doesn't print, nor does the
    closing the div tag.

    Can anyone suggest a place I should start to look for the problem? It
    doesn't seem possible it is here, though it looks that way.




    function mostRecentComme nts($number=10) {
    global $sql, $config;
    extract($config );
    // 06-17-03 - So the purpose of this function is to allow the
    designer to list blurbs from recent comments
    // in the margins. The number of comments returned is variable,
    depending on the number given as an argument
    // to the function. If it is 20 then the most recent 20 comments get
    returned. The title or headline of the
    // comment gets wrapped in a link so people can go read it, and from
    there of course, they can link back to
    // the page on which it is posted.
    $dbArray = $sql->getAllTypeFrom Db("comments") ;
    $dbArray = array_reverse($ dbArray);

    echo "<div class=\"recentC omments\">";
    echo "These are the most recent $number comments:<br>";
    for ($i=0; $i < $number; $i++) {
    $row = $dbArray[$i];
    $date = outputDate($row[3], 1);
    $commentLink = $pathToIndex."? comment[]=";
    $commentLink .= $row[0];
    $row[2] = substr($row[2], 0, 80);
    $row[2] = strip_tags($row[2]);
    echo "<div class=\"recentC ommentsEach\">< a
    class=\"recentC ommentLinks\" href=\"$comment Link\">\n";
    echo $row[1];
    echo "</a>\n";
    echo " - ";
    echo $row[2];
    echo "... ";
    echo "<br>\n";
    echo $date;
    echo "</div>\n\n";
    }
    echo "</div>";
    echo "this is us after the end";
    }
  • Tom Thackrey

    #2
    Re: function dying right in the middle of a for() loop, while simply doing a bunch of echo statements


    On 11-Jul-2003, lkrubner@geocit ies.com (lawrence) wrote:
    [color=blue]
    > Right now, over at www.monkeyclaus.org, the following script is
    > getting to the 9th run through and dying after the line:
    >
    > echo "...";
    >
    >
    > You'll admit that is a strange place to die. I've hit refresh several
    > times and it keeps happening. When I view page source, the last thing
    > that shows up is the "...". The date doesn't print, nor does the
    > closing the div tag.
    >
    > Can anyone suggest a place I should start to look for the problem? It
    > doesn't seem possible it is here, though it looks that way.
    >
    >
    >
    >
    > function mostRecentComme nts($number=10) {
    > global $sql, $config;
    > extract($config );
    > // 06-17-03 - So the purpose of this function is to allow the
    > designer to list blurbs from recent comments
    > // in the margins. The number of comments returned is variable,
    > depending on the number given as an argument
    > // to the function. If it is 20 then the most recent 20 comments get
    > returned. The title or headline of the
    > // comment gets wrapped in a link so people can go read it, and from
    > there of course, they can link back to
    > // the page on which it is posted.
    > $dbArray = $sql->getAllTypeFrom Db("comments") ;
    > $dbArray = array_reverse($ dbArray);
    >
    > echo "<div class=\"recentC omments\">";
    > echo "These are the most recent $number comments:<br>";
    > for ($i=0; $i < $number; $i++) {
    > $row = $dbArray[$i];
    > $date = outputDate($row[3], 1);
    > $commentLink = $pathToIndex."? comment[]=";
    > $commentLink .= $row[0];
    > $row[2] = substr($row[2], 0, 80);
    > $row[2] = strip_tags($row[2]);
    > echo "<div class=\"recentC ommentsEach\">< a
    > class=\"recentC ommentLinks\" href=\"$comment Link\">\n";
    > echo $row[1];
    > echo "</a>\n";
    > echo " - ";
    > echo $row[2];
    > echo "... ";
    > echo "<br>\n";
    > echo $date;
    > echo "</div>\n\n";
    > }
    > echo "</div>";
    > echo "this is us after the end";
    > }[/color]

    I assume you are looking at the source from the browser's point of view.
    That means that the script may not have died where you think because of
    buffering. My guess is that $dbArray has less than $number-1 elements.

    --
    Tom Thackrey

    Comment

    • lawrence

      #3
      Re: function dying right in the middle of a for() loop, while simply doing a bunch of echo statements

      "Tom Thackrey" <tomnr@creati ve-light.com> wrote in message[color=blue]
      > I assume you are looking at the source from the browser's point of view.
      > That means that the script may not have died where you think because of
      > buffering. My guess is that $dbArray has less than $number-1 elements.[/color]

      Thanks for the tip about buffering. That was a good tip. In fact, such
      strange things are happening with buffering that Netscape 7 will
      partially render the page, but AOL, using IE I think, gives me a "Page
      unavailable" error. Same page.

      I added a print_r($dbArra y) line to the function below, to test your
      idea that there are less that $number-1 elements. Actually, there are
      34 elements. (Logging in with phpMyAdmin and running the same query, I
      find that 34 is the correct number - exactly what should be expected).
      Again, Netscape 7 on a PC is willing to partially render the page. It
      stops rendering about 1/3 of the way throught the $dbArray but if you
      look at the page source the whole thing is there.

      Adding print_r($dbArra y) helped more of the page render. Netscape was
      willing to render a portion of the top right navigation bar, which is
      wasn't willing to do till I added the print_r() line. Needless to say,
      it is strange that adding print_r() should help a page render more.

      AOL, using IE, still refuses to render the page at all. Here's the
      function with the print_r line in it:






      function mostRecentComme nts($number=10) {
      global $sql, $config;
      extract($config );
      // 06-17-03 - So the purpose of this function is to allow the
      designer to list blurbs from recent comments
      // in the margins. The number of comments returned is variable,
      depending on the number given as an argument
      // to the function. If it is 20 then the most recent 20 comments get
      returned. The title or headline of the
      // comment gets wrapped in a link so people can go read it, and from
      there of course, they can link back to
      // the page on which it is posted.
      $dbArray = $sql->getAllTypeFrom Db("comments") ;
      $dbArray = array_reverse($ dbArray);
      print_r($dbArra y);
      echo "<div class=\"recentC omments\">";
      echo "These are the most recent $number comments:<br>";
      for ($i=0; $i < $number; $i++) {
      $row = $dbArray[$i];
      $date = outputDate($row[3], 1);
      $commentLink = $pathToIndex."? comment[]=";
      $commentLink .= $row[0];
      $row[2] = substr($row[2], 0, 80);
      $row[2] = strip_tags($row[2]);
      echo "<div class=\"recentC ommentsEach\">< a
      class=\"recentC ommentLinks\" href=\"$comment Link\">\n";
      echo $row[1];
      echo "</a>\n";
      echo " - ";
      echo $row[2];
      echo "... ";
      echo "<br>\n";
      echo $date;
      echo "</div>\n\n";
      }
      echo "</div>";
      echo "this is us after the end";
      }

      Comment

      Working...