If Else

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
oneofayykind
Forum Newbie
Posts: 6
Joined: Fri Sep 08, 2006 7:43 pm

If Else

Post 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.
Last edited by Benjamin on Tue Jun 09, 2009 5:12 pm, edited 1 time in total.
Reason: Changed code type from text to html.
User avatar
omniuni
Forum Regular
Posts: 738
Joined: Tue Jul 15, 2008 10:50 pm
Location: Carolina, USA

Re: If Else

Post by omniuni »

This is very confusing. I see almost no recognizable PHP. My thought, though, is to try looking for an elseif() statement.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: If Else

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply