Welcome Guest, Not a member yet? Register   Sign In
Problem with endif
#1

[eluser]tobbesanda[/eluser]
Hello there!

I'm new with CI but kind of familiar with PHP and I must say, This CI is really great! Damn I've saved time.

But now to my problem. I can't use endif or endforeach. I get parse error for some reason. It works ok if I open with { and close with }

I can't figure this out, anyone have an idea?

Greetings from Sweden!

/Tobias
#2

[eluser]Dam1an[/eluser]
Hi, welcome to CI

Can you post you're code please (using [ code ] tags)
#3

[eluser]tobbesanda[/eluser]
It's a simple code like:

Code:
<?php if (isset($navigation) && !empty($navigation)); ?>
<ul id="nav">

    &lt;?php foreach ($navigation as $nav); ?&gt;
    
    <li><a href="#">123</a></li>
    
    &lt;?php endforeach;?&gt;
    
</ul>
&lt;?php endif;?&gt;

It works if I use:

Code:
&lt;?php if (isset($navigation) && !empty($navigation)) { ?&gt;
<ul id="nav">

    &lt;?php foreach ($navigation as $nav) { ?&gt;
    
    <li><a href="#">123</a></li>
    
    &lt;?php } ?&gt;
    
</ul>
&lt;?php } ?&gt;

I find it really strange...
#4

[eluser]Dam1an[/eluser]
It should be
Code:
&lt;?php if (isset($navigation) && !empty($navigation)): ?&gt;
<ul id="nav">
    &lt;?php foreach ($navigation as $nav): ?&gt;
        <li><a href="#">123</a></li>
    &lt;?php endforeach;?&gt;
</ul>
&lt;?php endif;?&gt;

Colons for the opening statements, and a standard semi colon when you close the if/foreach
#5

[eluser]tobbesanda[/eluser]
hehe thx a lot! You go blind in front of all codes after a few hours =) Perhaps time for a break!

Thanks again for the quick reply.

/Tobias
#6

[eluser]Dam1an[/eluser]
Your welcome
Yeah, its so easy to miss these things, but thats the first thing I went to look for, cause I initially made the same mistake when I first used the alternative syntax
#7

[eluser]Thorpe Obazee[/eluser]
You probably need a better editor to 'see' these errors.
#8

[eluser]Dam1an[/eluser]
[quote author="bargainph" date="1242885929"]You probably need a better editor to 'see' these errors.[/quote]

If you're using a better editor (or IDE, such as Eclipse PDT in my case) it will autocomplete it for you so you don't get a chance to do it wrong Wink




Theme © iAndrew 2016 - Forum software by © MyBB