473,378 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Error with while Loop... very confusing!

35
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('content/pagination.php');

//from pagination.php
include('security/connect.php');
$getcount = mysql_query($nav_sql) or die('problem getting count: '.mysql_error());;
$total_results = mysql_result($getcount, 0) or die('problem getting total results: '.mysql_error());;
$total_pages = ceil($total_results / $max_results);
$nav_result = mysql_query($nav_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\">&nbsp;</div>";
$new_article_query = mysql_query("SELECT * FROM blog ORDER BY blogId DESC LIMIT 5");
while($new_article_row = mysql_fetch_row($new_article_query)) {
$titleLink2 = preg_replace('/ {1,}/', '_', trim($new_article_row[4]));
echo "<div><a href=\"http://www.confusinglygood.com/post/article/{$new_article_row[0]}/$titleLink2\">{$new_article_row[4]}</a></div>";
}
echo "<div class=\"spacer\">&nbsp;</div>";

echo $nav_sql;
$blog_result = mysql_query($nav_sql) or die('problem getting result for blog: '.mysql_error());

while($blogArray = mysql_fetch_array($blog_result) or die("Problem fetching array: ".mysql_error())) {
anything here always dies;
}
echo "</div>
<div class=\"spacer\">&nbsp;</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:
http://www.confusinglygood.com
You'll also see there that EVERYTHING else works fine. Anything, please :D

Thanks!
Feb 15 '07 #1
2 2052
d3vkit
35
Well, it seems I can't delete this thread, so I guess I'll provide some closure. I solved the problem. I stupidly put "or die(mysql_error())" at the end of a couple loops which would return 1 or less results and so the loop wouldn't really need to loop (mysql_num_row which had 0 to loop through and so it would die). this seemed to be the problem, but it was VERY confusing. Thanks to anyone that looked the thread. Hopefully I don't make such a dumb mistake again :P
Feb 16 '07 #2
ronverdonk
4,258 Expert 4TB
There are no dumb mistakes! Everyone makes a mistake some time, so don't worry. Part of life. Good luck!

ronald :cool:
Feb 16 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

24
by: Andrew Koenig | last post by:
PEP 315 suggests that a statement such as do: x = foo() while x != 0: bar(x) be equivalent to while True:
2
by: dmiller23462 | last post by:
Hey guys, I'm back again....I've got the results displaying that I wanted but instead of having a "next" or "previous" link displayed I am getting the error msg below (I actually get the data that...
5
by: NanQuan | last post by:
I'm hoping someone can help me solve this error since I am at a total loss here. Usually I don't bother posting on any forums or groups on the internet and prefer to solve stuff myself but this is...
1
by: questionr | last post by:
There is a spell checker function which is written in VB Script. The function works well when tested seperately. But when the function is called from Java Script, the function shows an Error saying...
10
by: ale.of.ginger | last post by:
Greetings! I am trying to make a multiplayer (no AI, 2 person) game of tic tac toe in Python. So far it has been pretty simple. My only concern is with the win checking to see if a person has...
1
by: Eric | last post by:
When I run my script it gives error on the following line: strEmail = Right(strEmail, (Len(strEmail) - 1)) I enclose my code and the sample text file too Thanks,...
12
by: sam | last post by:
hi all, i'm starting to put together a program to simulate the performance of an investment portfolio in a monte carlo manner doing x thousand iterations and extracting data from the results. ...
22
by: Amali | last post by:
I'm newdie in c programming. this is my first project in programming. I have to write a program for a airline reservation. this is what i have done yet. but when it runs it shows the number of...
7
vikas251074
by: vikas251074 | last post by:
I am getting error above in following code since few days giving tension day and night. How can I solve this? I am facing since Oct.25. in line no. 362 After doing a lot of homework, I am...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.