Log in   Register a New Account

Accessify Forum - Discuss Website Accessibility

New to the forum?

Only an email address is required.

Register Here

Already registered? Log In

PHP 'if' problem

Reply with quote Hi all, could someone please help me before I tie bricks around my neck and throw myself in the Loch?

Consider the following PHP snippet:
Code:
<ul>

<?php

if ($thisPage=='webhome')

{echo '<li class="currentpage">Accessible Web Services

<ul>
<li><a href="/web/web-design.php"> - Design</a></li>
<li><a href="#"> - Evaluation</a></li>
<li><a href="#"> - Conversion</a></li>
</ul>';}

if ($thisPage=='webdesign')

{echo '<li><a href="/web/web-home">Web Services

<ul>
<li class="currentpage"> - Design</li>
<li><a href="/web/web-evaluation"> - Evaluation</a></li>
<li><a href="/web/web-conversion"> - Conversion</a></li>
</ul>';}

else
{echo '<li><a href="/web/web-home.php">Web Services</a>';}?></li>
</ul>


Basically, a menu with a sub-menu. Each page is given a unique name via php. In this case, if page is 'webhome', the class 'currentpage' is assigned and certain styling is applied. Obviously, the active page is also de-linked. No problems with this part.

The next 'if' is causing me grief however. Again, page name is checked and actions carried out accordingly. Here, the page webdesign is allocated the class 'currentpage' and styling applied. The styling works perfectly.

My problem is that, despite the second instance of the Design page not have an <a> tag, the link is still active on the actual Design page. The link in the first 'if' statement appears to be overriding the settings in the second 'if' statement.

Any ideas please? I know it's bound to be something blindingly obvious, but you know what it's like; stare at the code too long and you can't see the wood for the trees!

Cheers!
Reply with quote
Gary Miller wrote:

Code:

if ($thisPage=='webdesign')

{echo '<li><a href="/web/web-home">Web Services


I think you'll find you are missing an </a>.

my mind is on a permanent tangent
Reply with quote Well...that took all of about 10 secs to insert, upload and check!!! Embarassed

Thanks Rich; sometimes, you just kind've get too immersed in things...

Laughing
Reply with quote took me a while to spot it too Smile

my mind is on a permanent tangent
Reply with quote For future references, Brugbart has a Tutorial on If Then Else and ElseIf Statements
Reply with quote I think you to verify the syntax of if and if else statement.
Reply with quote It is not problem. I think that php is the simple and common langguage and used more than other langguage.
Reply with quote Would it not make better sense to apply the 3 equal signs? That way it also compares the type, and you avoid problems such as if (0 == 'whatever').
Reply with quote Changes since the previous release candidate include:

Further bug fixes in the built-in web server.
PHP-FPM is no longer marked as EXPERIMENTAL.
Several improvements and bug fixes in the Zend Engine, Core and other extensions.
Reply with quote Your coding seems some internal problem when loop being execute. You try in the following format.

<?php
$myNodesID = arg(1);
$taxArray=taxonomy_node_get_terms($myNodesID);

if (($taxArray[1]->name == "News") || (arg(0) == "taxonomy" && arg(1) == "term" && arg(2) == 1))
{
return TRUE;
}
else {
return FALSE;
}
?>


[link removed by admin]

Display posts from previous:   

All times are GMT

  • Reply to topic
  • Post new topic