www.webdeveloper.com
Results 1 to 10 of 10

Thread: Can't see problem of syntax failing nav bar to load.

Hybrid View

  1. #1
    Join Date
    Apr 2013
    Posts
    12

    Can't see problem of syntax failing nav bar to load.

    Hey all I'm trying to create this navbar tutorial http://line25.com/tu...s-dropdown-menu, but with php so it show's what page the user is currently on.

    This is the php inside my nav.php:

    PHP Code:
    <?php
    echo '<div id="nav">';

    $whatpage basename($_SERVER['PHP_SELF']);
    echo 
    '<ul>';
    echo 
    '<li>';
        
        if (
    $whatpage == 'index.php') {
                echo 
    '<a href="index-1.php" class="highlight">home</a>';
                    } else {
                                echo 
    '<ahref="index-1.php">home</a>';
                                }
                                echo 
    '</li>';
            
            echo 
    '<li>';
                if (
    $whatpage == 'portfolio.php' || or '17.bedf.php' || or '12cur.php' || or 'bhl.php' || or 'alb.php' || or '5yeo.php' || or '96hsk.php' || or '11lgm.php' || or '12hon.php' || or '62elswt.php') {
                    echo 
    '<a href="portfolio.php class="highlight">portfolio</a>';
                } else {
                        echo 
    '<a href "portfolio.php">portfolio</a>';
                        }
                        
                
                echo 
    '<ul>';
                    echo 
    '<li>traditional stairs';
                        echo 
    '<ul>';
                            echo 
    '<li><a href="17.bedf.php">concrete stairs - covent garden</a></li>';
                            echo 
    '<li><a href="12cur.php">rc stairs - mayfair</a></li>';
                            echo 
    '<li><a href="bhl.php">half landing concrete stairs</a></li>';
                            echo 
    '<li><a href="alb.php">non slip concrete treads - london bridge</a></li>';
                            echo 
    '<li><a href="5yeo.php">concrete stairs - knightsbridge</a></li>';
                        echo 
    '</ul>';
                    echo 
    '</li>';
                echo 
    '</ul>';    
                        echo 
    '<li>complex concrete stairs';
                            echo 
    '<ul>';
                                echo 
    '<li><a href="96hsk.php">spiral concrete stairs - kensington</a></li>';
                                echo 
    '<li><a href="11lgm.php">curved concrete staircase - battersea</a></li>';
                                echo 
    '<li><a href="62elswt.php">helical concrete stairs - st johns wood</a></li>';
                            echo 
    '</ul>';
                        echo 
    '</li>';
                echo 
    '</ul>';
            echo 
    '</ul>';
                    
    echo 
    '</div>';
    ?>
    Validator checks are showing an error on line 16 (the one with many conditions seperated by double pipe characters ||.


    As it stands live at: http://www.concretes....uk/index-1.php



    I haven't messed around with css formatting at all yet (apart from class="highlight" mainly) but I seem to completely mess up my page when I'm trying to load it.



    I have an index.php which uses <?php
    include('nav.php');
    ?> to bring the navbar into the index page.



    My list is live at http://www.concretes...complex-ul.html just incase I have missed anything; here is the html5 that is on that url:
    HTML Code:
    <div id="nav">
    	<ul>
        	<li><a href="index.php">home</a></li>
            <li><a href="concrete stairs.php">concrete stairs</a>
            	<ul>
                	<li>traditional stairs
                    	<ul>
                        	<li><a href="17.bedf.php">concrete stairs - covent garden</a></li>
                            <li><a href="12cur.php">rc stairs - mayfair</a></li>
                            <li><a href="bhl.php">half landing concrete stairs</a></li>
                            <li><a href="alb.php">non slip concrete treads - london bridge</a></li>
                            <li><a href="5yeo.php">concrete stairs - knightsbridge</a></li>
    					</ul>
    				</li>
    				
    				
                        <li>complex concrete stairs
                    		<ul>
                        		<li><a href="96hsk.php">spiral concrete stairs - kensington</a></li>
                            	<li><a href="11lgm.php">curved concrete staircase - battersea</a></li>
                            	<li><a href="62elswt.php">helical concrete stairs - st john's wood</a></li>
    						</ul>
    					</li>
    			</ul>
    	</ul>
                    
    </div>
    Greatful for any advice, as I'm close but yet so far.

  2. #2
    Join Date
    Apr 2013
    Posts
    56
    You are using double or operator. || already counts as operator. Either use || or "or". You cannot use them both at the same time.

  3. #3
    Join Date
    Apr 2013
    Posts
    12
    Quote Originally Posted by coding123 View Post
    Either use || or "or".
    Thanks coding, isn't || exactly the same as what I currently have?

  4. #4
    Join Date
    Apr 2013
    Posts
    12
    Sorry, is that two forward slashes you have put?

  5. #5
    Join Date
    Apr 2013
    Posts
    56
    They are double vertical bars, not slashes.

  6. #6
    Join Date
    Apr 2013
    Posts
    12
    Massive thank you coding, really appreciate it.

  7. #7
    Join Date
    Oct 2012
    Posts
    41
    You are generating three link tags in your php code which are not valid HTML and will very likely break your page layout or at the least prevent the link working.

    <ahref="index-1.php">home</a>

    should be a space between the a and the href

    <a href="index-1.php">home</a>

    <a href="portfolio.php class="highlight">portfolio</a>'

    no closing double quote on the href attribute

    <a href "portfolio.php">portfolio</a>

    should be an equals sign after the href

  8. #8
    Join Date
    Apr 2013
    Posts
    12
    Fantastic, well noticed rh, I've scanned it myself constantly for a couple of hours and couldn't spot this.

    Many thanks.

  9. #9
    Join Date
    Apr 2013
    Posts
    12

    Problem determining current page

    Thanks for all your help on this guys; greatly appreciated. I'm going to turn this into a horizontal drop down list, but before I play with the css I'm trying to make sure php is working properly.

    I use class="highlight" to change colour of the active page. So at the moment it's live at http://www.concretestairslondon.co.uk/index-1.php but I just looked at the source code of the page being generated.

    As the current page is index1.php that should being echoed out as class="highlight". But it is being displayed as normal (the else statement).

    Also portfolio.php is being echoed as class="highlight", so it thinks it's on one of the portfolio pages.

    So my function must not be working properly; $whatpage = basename($_SERVER['PHP_SELF']);

    This is my current list being generated by php:
    PHP Code:
    <?php
    echo '<div id="nav">';

    $whatpage basename($_SERVER['PHP_SELF']);
    echo 
    '<ul>';
    echo 
    '<li>';
        
        if (
    $whatpage == 'index.php') {
                echo 
    '<a href="index-1.php" class="highlight">home</a>';
                    } else {
                                echo 
    '<a href="index-1.php">home</a>';
                                }
                                echo 
    '</li>';
            
            echo 
    '<li>';
                if (
    $whatpage == 'portfolio.php' or '17.bedf.php' or '12cur.php' or 'bhl.php' or 'alb.php' or '5yeo.php' or '96hsk.php' or '11lgm.php' or '12hon.php' or '62elswt.php') {
                    echo 
    '<a href="portfolio.php" class="highlight">portfolio</a>';
                } else {
                        echo 
    '<a href="portfolio.php">portfolio</a>';
                        }
                        
                
                echo 
    '<ul>';
                    echo 
    '<li>traditional stairs';
                        echo 
    '<ul>';
                            echo 
    '<li><a href="17.bedf.php">concrete stairs - covent garden</a></li>';
                            echo 
    '<li><a href="12cur.php">rc stairs - mayfair</a></li>';
                            echo 
    '<li><a href="bhl.php">half landing concrete stairs</a></li>';
                            echo 
    '<li><a href="alb.php">non slip concrete treads - london bridge</a></li>';
                            echo 
    '<li><a href="5yeo.php">concrete stairs - knightsbridge</a></li>';
                        echo 
    '</ul>';
                    echo 
    '</li>';    
                        echo 
    '<li>complex concrete stairs';
                            echo 
    '<ul>';
                                echo 
    '<li><a href="96hsk.php">spiral concrete stairs - kensington</a></li>';
                                echo 
    '<li><a href="11lgm.php">curved concrete staircase - battersea</a></li>';
                                echo 
    '<li><a href="62elswt.php">helical concrete stairs - st johns wood</a></li>';
                            echo 
    '</ul>';
                        echo 
    '</li>';
                echo 
    '</ul>';

    if (
    $whatpage == 'faq.php') {
        echo 
    '<li><a href="faq.php" class="highlight">faq\'s</a>';
        } else {
            echo 
    '<li><a href="faq.php">faq\'s</a>';
        }

    if (
    $whatpage == 'downloads.php') {
        echo 
    '<li><a href="downloads.php" class="highlight">downloads</a>';
        } else {
            echo 
    '<li><a href="downloads.php">downloads</a>';
        }
        
    if (
    $whatpage == 'contact.php') {
        echo 
    '<li><a href="contact.php" class="highlight">contact us</a>';
        } else {
            echo 
    '<li><a href="contact.php">contact us</a>';
        }
    echo 
    '</ul>';

                    
    echo 
    '</div>';
    ?>
    Thanks for any help. So embarassing.

  10. #10
    Join Date
    Apr 2013
    Posts
    12
    This must be where the problem is. I have it working well on the pages in the first <ul>. If I'm on the page it echoes out class="highlight". So the navbar is highlighted so we can see what page we're on.

    The original <ul> then goes into another couple of nested lists.
    The problem either lies in the multi conditioned if statement or in the actual list itself. I think it's gotta be something in the multi condition thing as others have used the <ul> I have.
    I've included the rest of the list incase there is a problem with the list format; I don't think it's the list, but I do know nothing lol.

    PHP Code:
    echo '<li>';
                if (
    $whatpage == 'portfolio.php' || '17.bedf.php' || '12cur.php' || 'bhl.php' || 'alb.php' || '5yeo.php' || '96hsk.php' || '11lgm.php' || '12hon.php' || '62elswt.php') {
                    echo 
    '<a href="portfolio.php" class="highlight">portfolio</a>';
                } else {
                        echo 
    '<a href="portfolio.php">portfolio</a>';
                        }
                        
                
                echo 
    '<ul>';
                    echo 
    '<li>traditional stairs';
                        echo 
    '<ul>';
                            echo 
    '<li><a href="17.bedf.php">concrete stairs - covent garden</a></li>';
                            echo 
    '<li><a href="12cur.php">rc stairs - mayfair</a></li>';
                            echo 
    '<li><a href="bhl.php">half landing concrete stairs</a></li>';
                            echo 
    '<li><a href="alb.php">non slip concrete treads - london bridge</a></li>';
                            echo 
    '<li><a href="5yeo.php">concrete stairs - knightsbridge</a></li>';
                        echo 
    '</ul>';
                    echo 
    '</li>';    
                        echo 
    '<li>complex concrete stairs';
                            echo 
    '<ul>';
                                echo 
    '<li><a href="96hsk.php">spiral concrete stairs - kensington</a></li>';
                                echo 
    '<li><a href="11lgm.php">curved concrete staircase - battersea</a></li>';
                                echo 
    '<li><a href="62elswt.php">helical concrete stairs - st johns wood</a></li>';
                            echo 
    '</ul>';
                        echo 
    '</li>';
                echo 
    '</ul>'

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles