Okay so I can NOT get my while loop to work. It's the most confusing thing I've ever come across. It was working fine and then suddenly, nothing. No error. The page just dies.
I am using PHP5 with mysql. Same problem in Fx 2.0 and IE 7.
I have the query sort of spread out across three pages to make it easier for me to generate it; I have a pagination script which checks what is being accessed from the query string (is it the whole blog or an individual entry?). This was all working great until last night. My data is there, and other queries to the db are working FINE; my tag cloud and 'newest articles' header are both functioning.
But my main page is simply dying.
Here is the code used, from the different pages, all at once. I have echoed everything out and I can find no errors.
[php]//from nav.setup.php
default:
$page = 1;
$max_results = 10;
$from = (($page * $max_results) - $max_results);
$nav_sql = "SELECT * FROM `blog` ORDER BY `blogId` DESC LIMIT $from, $max_results";
$nav_sqlcount = "SELECT count(*) AS num FROM blog";
//die('Died at default: '.$sql.'<br />'.$sqlcount) ;
include('conten t/pagination.php' );
//from pagination.php
include('securi ty/connect.php');
$getcount = mysql_query($na v_sql) or die('problem getting count: '.mysql_error() );;
$total_results = mysql_result($g etcount, 0) or die('problem getting total results: '.mysql_error() );;
$total_pages = ceil($total_res ults / $max_results);
$nav_result = mysql_query($na v_sql) or die('problem getting result: '.mysql_error() );
$fr = $from + 1;
$to = $from + mysql_num_rows( $nav_result);
//from main page
<?php
echo "<div id=\"blogDiv\">
<div>Newest Articles</div>
<div class=\"spacer\ "> </div>";
$new_article_qu ery = mysql_query("SE LECT * FROM blog ORDER BY blogId DESC LIMIT 5");
while($new_arti cle_row = mysql_fetch_row ($new_article_q uery)) {
$titleLink2 = preg_replace('/ {1,}/', '_', trim($new_artic le_row[4]));
echo "<div><a href=\"http://www.confusingly good.com/post/article/{$new_article_r ow[0]}/$titleLink2\">{ $new_article_ro w[4]}</a></div>";
}
echo "<div class=\"spacer\ "> </div>";
echo $nav_sql;
$blog_result = mysql_query($na v_sql) or die('problem getting result for blog: '.mysql_error() );
while($blogArra y = mysql_fetch_arr ay($blog_result ) or die("Problem fetching array: ".mysql_error() )) {
anything here always dies;
}
echo "</div>
<div class=\"spacer\ "> </div>";
?>[/php]
The echoed query looks fine.
I removed all the info between the while loop because it doesn't matter what I put there, it simply dies. If I take the while loop out, it is blank (of course), but at least doesn't die and gets to the rest of the code (footer etc). This is what has led me to believe that it is a problem with the while loop.
ANY ideas greatly appreciated!
To see the error in action:
You'll also see there that EVERYTHING else works fine. Anything, please :D
Thanks!
I am using PHP5 with mysql. Same problem in Fx 2.0 and IE 7.
I have the query sort of spread out across three pages to make it easier for me to generate it; I have a pagination script which checks what is being accessed from the query string (is it the whole blog or an individual entry?). This was all working great until last night. My data is there, and other queries to the db are working FINE; my tag cloud and 'newest articles' header are both functioning.
But my main page is simply dying.
Here is the code used, from the different pages, all at once. I have echoed everything out and I can find no errors.
[php]//from nav.setup.php
default:
$page = 1;
$max_results = 10;
$from = (($page * $max_results) - $max_results);
$nav_sql = "SELECT * FROM `blog` ORDER BY `blogId` DESC LIMIT $from, $max_results";
$nav_sqlcount = "SELECT count(*) AS num FROM blog";
//die('Died at default: '.$sql.'<br />'.$sqlcount) ;
include('conten t/pagination.php' );
//from pagination.php
include('securi ty/connect.php');
$getcount = mysql_query($na v_sql) or die('problem getting count: '.mysql_error() );;
$total_results = mysql_result($g etcount, 0) or die('problem getting total results: '.mysql_error() );;
$total_pages = ceil($total_res ults / $max_results);
$nav_result = mysql_query($na v_sql) or die('problem getting result: '.mysql_error() );
$fr = $from + 1;
$to = $from + mysql_num_rows( $nav_result);
//from main page
<?php
echo "<div id=\"blogDiv\">
<div>Newest Articles</div>
<div class=\"spacer\ "> </div>";
$new_article_qu ery = mysql_query("SE LECT * FROM blog ORDER BY blogId DESC LIMIT 5");
while($new_arti cle_row = mysql_fetch_row ($new_article_q uery)) {
$titleLink2 = preg_replace('/ {1,}/', '_', trim($new_artic le_row[4]));
echo "<div><a href=\"http://www.confusingly good.com/post/article/{$new_article_r ow[0]}/$titleLink2\">{ $new_article_ro w[4]}</a></div>";
}
echo "<div class=\"spacer\ "> </div>";
echo $nav_sql;
$blog_result = mysql_query($na v_sql) or die('problem getting result for blog: '.mysql_error() );
while($blogArra y = mysql_fetch_arr ay($blog_result ) or die("Problem fetching array: ".mysql_error() )) {
anything here always dies;
}
echo "</div>
<div class=\"spacer\ "> </div>";
?>[/php]
The echoed query looks fine.
I removed all the info between the while loop because it doesn't matter what I put there, it simply dies. If I take the while loop out, it is blank (of course), but at least doesn't die and gets to the rest of the code (footer etc). This is what has led me to believe that it is a problem with the while loop.
ANY ideas greatly appreciated!
To see the error in action:
You'll also see there that EVERYTHING else works fine. Anything, please :D
Thanks!
Comment