/    Sign up×
Community /Pin to ProfileBookmark

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

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

This is the php inside my nav.php:

[code=php]<?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>’;
?>[/code]

Validator checks are showing an error on line 16 (the one with many conditions seperated by double pipe characters ||.

As it stands live at: [URL=”http://www.concretes….uk/index-1.php”]http://www.concretes….uk/index-1.php
[/URL]

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 [URL=”http://www.concretes…complex-ul.html”]http://www.concretes…complex-ul.html[/URL] just incase I have missed anything; here is the html5 that is on that url:

[code=html]<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>[/code]

Greatful for any advice, as I’m close but yet so far.

to post a comment
PHP

9 Comments(s)

Copy linkTweet thisAlerts:
@coding123Apr 11.2013 — You are using double or operator. || already counts as operator. Either use || or "or". You cannot use them both at the same time.
Copy linkTweet thisAlerts:
@Dal123authorApr 11.2013 —  Either use || or "or". [/QUOTE]

Thanks coding, isn't || exactly the same as what I currently have?
Copy linkTweet thisAlerts:
@Dal123authorApr 11.2013 — Sorry, is that two forward slashes you have put?
Copy linkTweet thisAlerts:
@coding123Apr 11.2013 — They are double vertical bars, not slashes.
Copy linkTweet thisAlerts:
@Dal123authorApr 11.2013 — Massive thank you coding, really appreciate it.
Copy linkTweet thisAlerts:
@rh_lloydnorthovApr 12.2013 — 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
Copy linkTweet thisAlerts:
@Dal123authorApr 12.2013 — Fantastic, well noticed rh, I've scanned it myself constantly for a couple of hours and couldn't spot this.

Many thanks.
Copy linkTweet thisAlerts:
@Dal123authorApr 12.2013 — 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:
[code=php]<?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>';
?>
[/code]


Thanks for any help. So embarassing.
Copy linkTweet thisAlerts:
@Dal123authorApr 12.2013 — 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.

[code=php]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>';[/code]
×

Success!

Help @Dal123 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...