simple script - not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

simple script - not working

Post 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!
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Not sure what the problem is, but put an "echo $pageis;" line before your if clause - maybe it's getting changed somewhere.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post by djot »

-
Do you use functions? In menu.php? Make $pageis global then or use it as argument for the function.

djot
-
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post 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
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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;
}
User avatar
C_Calav
Forum Contributor
Posts: 395
Joined: Wed Jun 02, 2004 10:55 pm
Location: New Zealand

Post by C_Calav »

how can i apply this to what i am doing?
Post Reply