Jump to content

Output nothing when use loop, output fine when done manually


Ge64

Recommended Posts

I'm making a very simple app at the moment but I'm running into something I can't explain. I have a sql query which is succesful and the result is in $mysqlresult. Whenever I do the following, everything turns out fine (there are 2 rows):

 

$row = mysql_fetch_assoc($mysqlresult);
echo $row['data'];

mysql_data_seek($mysqlresult, 1);

$row = mysql_fetch_assoc($mysqlresult);
echo $row['data'];

 

But when I use the normal way:

 

while($row = mysql_fetch_assoc($mysqlresult))
{
    echo $row['data'];
} 

 

it doesn't output anything, not even anything I echo before or after that, as if PHP locks up on the loop.

 

I'm using the almost latest version of PHP.

Link to comment
Share on other sites

If you output something after the loop does the output appear?

 

Just to test you're not hitting an error that's not being displayed.

 

When developing, if you have access to the server, I always find it useful to have an SSH terminal open and tail the apache error log as sometimes

your errors end up in the log if they are parsing errors but not on screen.

Link to comment
Share on other sites

No, i have echo's and even just HTML after and before the php code and it doesn't output anything.

 

I actually have physical and SSH access to the server and I even had an ssh window open to test the mysql queries. I'll try to find the error log, but is there any way I can get the error to display through the browser instead?

Link to comment
Share on other sites

I found the log and found the problem

 

The problem was whitespace. When I removed the 4 spaces before the 'echo' command inside the loop, it worked. True, I copy/pasted the code from Safari (shame on me) but it appeared as normal spaces in BBEdit.

 

I put back new spaces and it still works so I suppose they weren't actually 'spaces'. This was the error:

 

[error] PHP Fatal error:  Call to undefined function \xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0echo() in /Users/ge64/Sites/knowledgebase/action.php on line 27

Link to comment
Share on other sites

a BBEdit tool that I use A LOT when copying/pasting from the web is Text > Zap Gremlins...

 

That command finds all invisible code-crashing stuff and can either delete it or replace it with something else. I often replace with a bullet (on OS X, Alt-8) to find oddities in HTML, or simply replace with a space for PHP copied from here and elsewhere.

 

FYI.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.