/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Simple if, else statement question?

I have the following code that is not working. Basically depending on which page is selected, it changes which link is active. The only problem is this only works if I am viewing the index.php. Any Help

[code=php]<?php
$pid = $_GET[‘pid’];
if ($pid == 01 || $pid = “”)
echo “<li class=’active’><a href=’index.php?pid=01′>Home</a></li>”;
else
echo “<li><a href=’index.php?pid=01′>Home</a></li>”;
if ($pid == 02)
echo “<li class=’active’><a href=’businesses.php?pid=02′>Area Businesses</a>
<ul>
<li><a href=’businesses.php?pid=02′>Businesses</a></li>
<li><a href=’churches.php?pid=04′>Churches</a></li>
</ul>
</li>”;
else
echo “<li><a href=’businesses.php?pid=02′>Area Businesses</a>
<ul>
<li><a href=’businesses.php?pid=02′>Businesses</a></li>
<li><a href=’churches.php?pid=04′>Churches</a></li>
</ul>
</li>”;
if ($pid == 05)
echo “<li class=’active’><a href=’schools.php?pid=05′>Schools</a>
<ul>
<li><a href=’#’>Elementry School</a></li>
<li><a href=’#’>Middle School</a></li>
<li><a href=’#’>High School</a></li>
</ul>
</li>”;
else
echo “<li><a href=’schools.php?pid=05′>Schools</a>
<ul>
<li><a href=’#’>Elementry School</a></li>
<li><a href=’#’>Middle School</a></li>
<li><a href=’#’>High School</a></li>
</ul>
</li>”;
if ($pid == 06)
echo “<li class=’last; active’><a href=’events.php?pid=06′>Events</a></li>”;
else
echo “<li class=’last’><a href=’events.php?pid=06′>Events</a></li>”;
?>[/code]

I am probably just missing something simple, so I need a second or third set of eyes on it.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@hyperionXSMar 26.2012 — Can you explain what exactly is not working ?
Copy linkTweet thisAlerts:
@tracknutMar 26.2012 — I'm guessing you wanted to compare here, not assign into $pid:
<i>
</i> if ($pid == 01 || $pid [COLOR="Red"]=[/COLOR] "")
Copy linkTweet thisAlerts:
@hamburglarMar 26.2012 — I'm guessing you wanted to compare here, not assign into $pid:
<i>
</i> if ($pid == 01 || $pid [COLOR="Red"]=[/COLOR] "")
[/QUOTE]


I think that will do it. I always overlook the 2 equal signs in an if statement.
Copy linkTweet thisAlerts:
@monarch_684authorApr 01.2012 — Thank You. Yes I wanted to compare. Didn't notice I was missing the other =
×

Success!

Help @monarch_684 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.28,
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,
)...