
December 20th, 2004
09:14 AM
Neverside Newbie
Status: Offline!
Function help
im pulling my hair out with this problem. i know im either doing something that cant be done or im missing something simple. i will try and explain this as easy as i can
in a include called functions i have this
<?
function homeTab()
{
if ( $section=="home" )
echo " id=\"current\"";
}
?>
on the page with the content i have this
<?
require('functions.php');
$section = home;
include('inc/head.php');
?>
and in the head include i have this to call the function
everything works fine but the function doesn't work. nothing gets outputted.
am i forgetting something when using the if statement in a function? cause if i put that exact same code in the site without a function it works

December 20th, 2004
09:46 AM
Neverside Newbie
Status: Offline!
i tried that too, but it doesnt help
im trying to make a modified version of this from alistapart. is there a reason why they left out the curly brackets?
http://www.alistapart.com/articles/keepingcurrent/
<div id="navigation">
<ul>
<li<?php if ($thisPage=="Page One")
echo " id=\"currentpage\""; ?>>
<a href="#">Page One</a></li>
<li<?php if ($thisPage=="Page Two")
echo " id=\"currentpage\""; ?>>
<a href="#">Page Two</a></li>
<li<?php if ($thisPage=="Page Three")
echo " id=\"currentpage\""; ?>>
<a href="#">Page Three</a></li>
<li<?php if ($thisPage=="Page Four")
echo " id=\"currentpage\""; ?>>
<a href="#">Page Four</a></li>
</ul>
</div>

December 20th, 2004
12:09 PM
Neverside Newbie
Status: Offline!
but what is currentpage? are you trying to make it output the current page?
___________________
<sig here>

December 20th, 2004
12:10 PM
Your $section variable should be declared global inside the function:
<?php
function homeTab()
{
global $section;
if ( $section=="home" )
echo " id=\"current\"";
}
?>
Or you can pass the data directly into the function, in which case it doesn`t need to be global.
<?php
function homeTab($section)
{
if ( $section=="home" )
echo " id=\"current\"";
}
?>
Also, a switch statement will run faster than multiple if`s.
Hope that helps. 
___________________
::M-Dream::
:: Asian Cinema :: Asian Music :: Chinese Astrology :: Free PHP Scripts
:: Asian Cover Scans :: Asian Photo Galleries

December 20th, 2004
12:15 PM
Neverside Newbie
Status: Offline!
ok, i had a feeling i needed to put something in the brackets. i will that
btw, if i put that globals stuff in there doesn't that override the variable and use the one in the function or only if it was like this:
<?php
$GLOBALS['section'] = "";
?>

December 20th, 2004
12:57 PM
website designer
Status: Offline!
btw, if youre getting an additional error
$section = home;
should be changed to
$section = "home";
currently, its checking to see if home is a constant, then assigning it as a string.
___________________

http://www.anatonic.com/

December 20th, 2004
01:31 PM
Neverside Newbie
Status: Offline!
so adding the variable to the brackets did the trick the code looks like this:
<?php
// HOME TAB
function homeTab($section)
{
if ( $section=="home" )
echo " id=\"current\"";
}
// SHOPPING TAB
function shoppingTab($section)
{
if ( $section=="shopping" )
echo " id=\"current\"";
}
// GIVING TAB
function givingTab($section)
{
if ( $section=="giving" )
echo " id=\"current\"";
}
?>
is there a more efficient way of doing this?