Forum Moderators: coopster

Message Too Old, No Replies

Are multiple OR statements the problem?

         

mr_nabo

5:27 pm on Jan 29, 2008 (gmt 0)

10+ Year Member



Hi,

I really can't figure out why my script isn't working other than thinking that I can't have multiple OR (¦) operators in my IF statement.

I want my script to hide a list of items unless the visitor is on a certain page - indicated by the variables.

Can anyone help me figure out why it's not working?

Thanks


<?php // page variables

$vb = 'index.php';
$vp = 'blah.php';
$vc = 'blah2.php';

// display the div if active page is found within it

function displaynav() {

$currentPage = end(explode('/', $_SERVER['REQUEST_URI']));

if ($currentPage!== $vb ¦ $vp ¦ $vc) {

echo ' style="display:none;"';

}

}

?>

sned

5:32 pm on Jan 29, 2008 (gmt 0)

10+ Year Member



Your 'if' statement needs to look like this:

if ($currentPage!== $vb ¦¦ $currentPage!== $vp ¦¦ $currentPage!== $vc)

It seems logical to do it the first way like you posted, but doing it that way, php thinks the other variables are just boolean (true / false).

-sned

mr_nabo

5:47 pm on Jan 29, 2008 (gmt 0)

10+ Year Member



Thanks for pointing that out. I'm just wondering how I might make this function into one that can take any variable and output 'style=="display:none;"'

If it's like the example below, then how would I specify multiple variables in my function?

Would it be like so?

displaynav($var1, $var2, $var3);

General function:


<?php

function displaynav($page) {

$currentPage = end(explode('/', $_SERVER['REQUEST_URI']));

if ($currentPage!== $page) {

echo ' style="display:none;"';

}

}

?>

maxximus

8:47 pm on Jan 29, 2008 (gmt 0)

10+ Year Member



Dont understand why you need display none on a certain page(why not just remove it altogether). Do you have another function to make it visble again. Is it dependent on a URL parameter.

You need to explain your problem. Something like below would work though.

<?php 

$allowed=array('index.php', 'blah.php', 'blah2.php');

$currentPage =basename( $_SERVER['PHP_SELF']);
if (in_array($currentPage, $allowed))
{
// your list goes here.
}

?>