Page 1 of 1

simple script - not working

Posted: Wed Jan 04, 2006 4:26 pm
by C_Calav
hi guys,

been a while since i did some php work and having a wee problem getting this simple script to work.

its not putting: id="current" into my list when its on that page.

its not

i have this in my main body

Code: Select all

$pageis = 'alc_sum_01'; 

include("menu.php");


and this in the menu.php

Code: Select all

if($pageis =="alc_sum_01")
   {
    print('<li><a href="/html/summer/alc_sum_01.php" onfocus="this.blur()" id="current" title="Greaser Tee">Greaser Tee</a></li>');
   }
  else
   {
    print('<li><a href="/html/summer/alc_sum_01.php" onfocus="this.blur()" title="Greaser Tee">Greaser Tee</a></li>');
   }

now i know this is a long way of doing it.. i am going to have a lot of if and else statments in my menu once i have finished...i should using SWITCH statments but i wanna get this working first i guess.

thanks guys any help would be great!

Posted: Wed Jan 04, 2006 4:33 pm
by pickle
Not sure what the problem is, but put an "echo $pageis;" line before your if clause - maybe it's getting changed somewhere.

Posted: Wed Jan 04, 2006 4:45 pm
by djot
-
Do you use functions? In menu.php? Make $pageis global then or use it as argument for the function.

djot
-

Posted: Wed Jan 04, 2006 4:51 pm
by C_Calav
ok i have got the script working now...


can someone show me a easier way to do this instead??

thanks for the reply djot, can you explain a bit further? yes i have used functions before

Posted: Wed Jan 04, 2006 5:00 pm
by John Cartwright
functions have a different variable scope than a normal page.. for example

Code: Select all

$someVariable = 'Hello World!';

//this will output nothing since fooBar() does not have access to the pages scope
function fooBar() {
   echo $someVariable;
}

//this will output Hello World! since we have passed $someVariable as an argument
function fooBar($someVariable) {
   echo $someVariable;
}

//this will output Hello World! since you have made the variable scope global for that particular variable
function fooBar() {
   global $someVariable;
   echo $someVariable;
}

Posted: Wed Jan 04, 2006 5:17 pm
by C_Calav
how can i apply this to what i am doing?