By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,702 Members | 1,101 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,702 IT Pros & Developers. It's quick & easy.

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

P: n/a
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 mostRecentComments($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->getAllTypeFromDb("comments");
$dbArray = array_reverse($dbArray);

echo "<div class=\"recentComments\">";
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=\"recentCommentsEach\"><a
class=\"recentCommentLinks\" href=\"$commentLink\">\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";
}
Jul 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

On 11-Jul-2003, lk******@geocities.com (lawrence) wrote:
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 mostRecentComments($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->getAllTypeFromDb("comments");
$dbArray = array_reverse($dbArray);

echo "<div class=\"recentComments\">";
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=\"recentCommentsEach\"><a
class=\"recentCommentLinks\" href=\"$commentLink\">\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";
}


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
www.creative-light.com
Jul 16 '05 #2

P: n/a
"Tom Thackrey" <to***@creative-light.com> wrote in message
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.


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($dbArray) 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($dbArray) 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 mostRecentComments($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->getAllTypeFromDb("comments");
$dbArray = array_reverse($dbArray);
print_r($dbArray);
echo "<div class=\"recentComments\">";
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=\"recentCommentsEach\"><a
class=\"recentCommentLinks\" href=\"$commentLink\">\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";
}
Jul 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.