Page 1 of 1

If Else

Posted: Tue Jun 09, 2009 3:25 pm
by oneofayykind
I'm creating a nav bar that will show one thing if the user isn't logged in and another if the user is logged in. I have created it successfully but I don't believe its working like it should although it seems like it does...I'm altering the code from the phpbb 3.0 forum.

The code is this

Code: Select all

<!-- IF not S_USER_LOGGED_IN and not S_IS_BOT -->
          <div class="navbar">
            <div class="inner"><span class="corners-top"><span></span></span>
                 <ul class="linklist navlinks">
                    <li class="forum-home"><a href="{U_INDEX}" title="{L_INDEX}">Forum Home</a></li>
                <li <fieldset class="icon-faq"><a href="{U_FAQ}" title="{L_FAQ_EXPLAIN}">{L_FAQ}</a></fieldset></li>
                <li><form method="post" action="{S_LOGIN_ACTION}" class="headerspace">
                <!-- IF S_REGISTER_ENABLED --><a href="{U_REGISTER}">{L_REGISTER_HOME}</a><!-- ENDIF -->
                <li><fieldset class="quick-login">
             <label for="username">{L_USERNAME}:</label><input type="text" name="username" id="username" size="10" class="inputbox" title="{L_USERNAME}" /><!-- IF S_AUTOLOGIN_ENABLED --><label for="autologin">{L_LOG_ME_IN} <input type="checkbox" name="autologin" id="autologin" /></label></li>
             <!-- ENDIF --> 
             <li><fieldset class="quick-login1">
                <label for="password">{L_PASSWORD}:</label><input type="password" name="password" id="password" size="10" class="inputbox" title="{L_PASSWORD}" /></br>
                <input type="submit" name="login" value="{L_LOGIN}" class="button2" />
             </fieldset></li>
             <!-- IF S_DISPLAY_SEARCH and not S_IN_SEARCH -->
                <li><div id="search-box" style="cursor: pointer;">
                </fieldset>
                <form action="{U_SEARCH}" method="post" id="search">
                  <fieldset>
                    <input name="keywords" id="keywords" type="text" maxlength="128" title="{L_SEARCH_KEYWORDS}" class="inputbox search" value="<!-- IF SEARCH_WORDS-->{SEARCH_WORDS}<!-- ELSE -->{L_SEARCH_MINI}<!-- ENDIF -->" onclick="if(this.value=='{LA_SEARCH_MINI}')this.value='';" onblur="if(this.value=='')this.value='{LA_SEARCH_MINI}';" />
                    <input class="button2" value="{L_SEARCH}" type="submit" /><br />
                    <a href="{U_SEARCH}" title="{L_SEARCH_ADV_EXPLAIN}">{L_SEARCH_ADV}</a> {S_SEARCH_HIDDEN_FIELDS}
                  
             <!-- ENDIF -->
                </fieldset>
               </form>
                <li class="icon-home"><a href="{U_INDEX}" accesskey="h">{L_INDEX}</a> <!-- BEGIN navlinks --> <strong>&#8249;</strong> <a href="{navlinks.U_VIEW_FORUM}">{navlinks.FORUM_NAME}</a><!-- END navlinks --></li>
 
                
             </ul>
               
                <!-- ELSE IF S_USER_LOGGED_IN and S_IS_BOT -->
          <div class="navbar">
            <div class="inner"><span class="corners-top"><span></span></span>
                 <ul class="linklist1 navlinks1">
                    <li class="forum-home"><a href="{U_INDEX}" title="{L_INDEX}">Forum Home</a></li>
                    <!-- IF not S_IS_BOT and S_USER_LOGGED_IN -->
                <li class="icon-ucp">
                   <a href="{U_PROFILE}" title="{L_PROFILE}" accesskey="u">{L_PROFILE}</a>
                </li>
                <li <fieldset class="icon-faq"><a href="{U_FAQ}" title="{L_FAQ_EXPLAIN}">{L_FAQ}</a></fieldset></li>
                <li class="icon-logout"><a href="{U_LOGIN_LOGOUT}" title="{L_LOGIN_LOGOUT}" accesskey="l">{L_LOGIN_LOGOUT}</a></li> 
             <!-- IF S_DISPLAY_SEARCH and not S_IN_SEARCH -->
                <li><div id="search-box" style="cursor: pointer;">
                </fieldset>
                <form action="{U_SEARCH}" method="post" id="search">
                  <fieldset>
                    <input name="keywords" id="keywords" type="text" maxlength="128" title="{L_SEARCH_KEYWORDS}" class="inputbox search" value="<!-- IF SEARCH_WORDS-->{SEARCH_WORDS}<!-- ELSE -->{L_SEARCH_MINI}<!-- ENDIF -->" onclick="if(this.value=='{LA_SEARCH_MINI}')this.value='';" onblur="if(this.value=='')this.value='{LA_SEARCH_MINI}';" />
                    <input class="button2" value="{L_SEARCH}" type="submit" /><br />
                    <a href="{U_SEARCH}" title="{L_SEARCH_ADV_EXPLAIN}">{L_SEARCH_ADV}</a> {S_SEARCH_HIDDEN_FIELDS}
                  
             <!-- ENDIF -->
                <!-- ENDIF -->
                <!-- ENDIF -->


Could someone tell me if this is correct? It works properly cause if you logged in it shows the other nav but anything after the ELSE i can change and it doesn't matter it still shows the nav after log in.

What I'm ultimately looking to accomplish is add another else so the first else looks to see if the user is logged in and is not a moderator and shows that nav and then and else that looks to see if the user is logged in and is a moderator and shows a different nav.

I would appreciate any help and sorry if I posted in the wrong place.

Re: If Else

Posted: Tue Jun 09, 2009 8:25 pm
by omniuni
This is very confusing. I see almost no recognizable PHP. My thought, though, is to try looking for an elseif() statement.

Re: If Else

Posted: Wed Jun 10, 2009 11:33 am
by pickle
I'd recommend reformatting your code so the if...else statements are arranged like you would arrange PHP code ie: properly indented & not inline. That will help everyone understand the code better.