Jump to content

Help creating a function...


DBookatay

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/87126-help-creating-a-function/
Share on other sites

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

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.