DBookatay Posted January 21, 2008 Share Posted January 21, 2008 Hello all... I need help creating a function that will determine what css class should be used. I am working on a Glossary page, that has a navigation menu on the right. (http://www.carcityofdanbury.com/text.php?category=Glossary&Ltr=A) I am trying to make it that if the user is under the "A" section, the nav link class <a class="glossLtr" href="text.php?category=Glossary&Ltr=A">A</a> is "glossLtrOn", and if it is not, say letter "B" it uses the default class: "glossLtr". Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/87126-help-creating-a-function/ Share on other sites More sharing options...
taith Posted January 21, 2008 Share Posted January 21, 2008 a) this isnt a function... and b) it depends 100% on the rest of your page's setup... for example foreach($letters as $k=>$v){ if($k==$_GET[ltr]) $class='glossLtrOn'; else $class='glossLtr'; } Quote Link to comment https://forums.phpfreaks.com/topic/87126-help-creating-a-function/#findComment-445603 Share on other sites More sharing options...
DBookatay Posted January 21, 2008 Author Share Posted January 21, 2008 a) this isnt a function... and b) it depends 100% on the rest of your page's setup... for example foreach($letters as $k=>$v){ if($k==$_GET[ltr]) $class='glossLtrOn'; else $class='glossLtr'; } Warning: Invalid argument supplied for foreach() in /home/.phillipina/dbookatay/carcityofdanbury.com/text.php on line 42 Quote Link to comment https://forums.phpfreaks.com/topic/87126-help-creating-a-function/#findComment-445608 Share on other sites More sharing options...
taith Posted January 21, 2008 Share Posted January 21, 2008 as i said... it depends 100% on your site setup... Quote Link to comment https://forums.phpfreaks.com/topic/87126-help-creating-a-function/#findComment-445611 Share on other sites More sharing options...
DBookatay Posted January 21, 2008 Author Share Posted January 21, 2008 as i said... it depends 100% on your site setup... What do you mean? How is this done then? Quote Link to comment https://forums.phpfreaks.com/topic/87126-help-creating-a-function/#findComment-445614 Share on other sites More sharing options...
teng84 Posted January 21, 2008 Share Posted January 21, 2008 <?php function CSS($var){ switch($var){ case 'A': $css = 'style1'; break; case 'B': $css = 'style2'; break; case 'C': $css = 'style2'; break; default: $css = 'default style'; break; } return $css; } //sample usage $css = CSS($_GET['Ltr']); echo '<a class="'.$css.'" href="text.php?category=Glossary&Ltr=A">A</a>';' ?> try note not tested but it should work Quote Link to comment https://forums.phpfreaks.com/topic/87126-help-creating-a-function/#findComment-445629 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.