Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.