Reply to Re: unexpected ELSE

Your name:

Reply:


Posted by Tim Streater on 03/30/06 18:24

In article <16qdnZbt75oqx7rZRVn-sQ@comcast.com>,
"Jim Michaels" <NOSPAMFORjmichae3@yahoo.com> wrote:

> C:\prj\quiz\withusers>php tareports.php
> PHP Parse error: syntax error, unexpected T_ELSE in
> C:\prj\quiz\withusers\tareports.php on line 205
>
>
> this is the section of code.
>
> if (isset($row4)) {
> if (isset($row5)) { //answer given?
> if ($row4['answer_tag']==$row5['answer_tag']) {
> ?>
> <div class=answer>Answer:<br />
> <?php echo $row4['answer_tag']; ?>. <?php echo $row5['answer']; ?><?php if
> ($row5['is_img']) { ?><img src="<?php echo getconfigvar("basepath");
> ?>viewraimg.php?id=<?php echo $row5['answer_id']; ?>" /><?php } ?>
> </div>
> <br />
> <?php
> $ncorrect++;
> } else { //no answer or answer is wrong
> ?>
> <div class=answer>Answer 1:<br />
> <?php echo $row5['answer_tag']; ?>. <?php echo $row5['answer']; ?><?php if
> ($row5['is_img']) { ?><img src="<?php echo getconfigvar("basepath");
> ?>viewraimg.php?id=<?php echo $row5['answer_id']; ?>" /><?php } ?>
> </div>
> <div class=answer>Answer 2:<br />
> <?php echo $row4['answer_tag']; ?>. <?php echo $row4['answer']; ?><?php if
> ($row4['is_img']) { ?><img src="<?php echo getconfigvar("basepath");
> ?>viewraimg.php?id=<?php echo $row4['answer_id']; ?>" /><?php } ?>
> </div>
> <br />
> <?php
> $nwrong++;
> }
>
> ...else blah blah
>
>
> I need a 2nd pair of eyes. I've gone as far as I can debugging this thing.
> my braces match. I even eliminated a stray open switch statement that I
> copied from code elsewhere. Am I running into a PHP parser bug that doesn't
> like certain IF constructs here?
>
> I once got an error message about an unexpected } because one was missing in
> my code or something like that. It was an odd error message for the problem.
> and I think I am getting another one of these.

Not that this is going to help but ...

I have to say I find code laid out like this to be unreadable. I tend to
line up ifs, elses, and braces so I can easily see where blocks start
and end and which else matches with which if. Is it tedious to do this?
A bit but it saves huge amounts of time. For editing I use TextWrangler
as that gives syntax-colouring - useful when you have lots of quotes
kicking about.

Also if you have lots of nested ifs and elses you probably want to
rethink what you are doing and how you are doing it.

-- tim

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация