开发者

Fixing Current Tab Color using 1 php file only

im sorry for the poor title, i dont know how to explain it. You see i have already created my panel tabs with the help of ol, li and css. it is working perfectly but then there is one problem that occured in the program. this tab li class="current"

the purpose of the class=current that is set in a specified link will help change the background image of the active link. the css code for that is already set and working. I will first show you the codes i used here:

<ol id="toc">
                <li>&nbsp;&nbsp;&nbsp;</li>
                <li class="current"><a href="index.php"><span>#</span></a></li>
                <li><a href="index.php?namelist=a"><span>A</span></a></li>          
                <li><a href="index.php?namelist=b"><span>B</span></a></li>              
                <li><a href="index.php?namelist=c"><span>C</span></a></li>      
                <li><a href="index.php?namelist=d"><span>D</span></a></li>          
                <li><a href="index.php?namelist=e"><span>E</span></a></li>          
                <li><a href="index.php?namelist=f"><span>F</span></a></li>          
                <li><a href="index.php?namelist=g"><span>G</span></a></li>
                <li><a href="index.php?namelist=h"><span>H</span></a></li>          
                <li><a href="index.php?namelist=i"><span>I</span></a></li>              
                <li><a href="index.php?namelist=j"><span>J</span></a></li>              
                <li><a href="index.php?namelist=k"><span>K</span></a></li>      
                <li><a href="index.php?namelist=l"><span>L</span></a></li>      
                <li><a href="index.php?namelist=m"><span>M</span></a></li>                  
                <li><a href="index.php?namelist=n"><span>N</span></a></li>      
                <li><a href="index.php?namelist=o"><span>O</span></a></li>开发者_开发知识库;          
                <li><a href="index.php?namelist=p"><span>P</span></a></li>          
                <li><a href="index.php?namelist=q"><span>Q</span></a></li>          
                <li><a href="index.php?namelist=r"><span>R</span></a></li>              
                <li><a href="index.php?namelist=s"><span>S</span></a></li>                  
                <li><a href="index.php?namelist=t"><span>T</span></a></li>          
                <li><a href="index.php?namelist=u"><span>U</span></a></li>              
                <li><a href="index.php?namelist=v"><span>V</span></a></li>  
                <li><a href="index.php?namelist=w"><span>W</span></a></li>          
                <li><a href="index.php?namelist=x"><span>X</span></a></li>          
                <li><a href="index.php?namelist=y"><span>Y</span></a></li>              
                <li><a href="index.php?namelist=z"><span>Z</span></a></li>
                </ol>   

as you can see here is the list of links that i have. its purpose is to search the employee name and information from the database and output in on the next tags where the name of the employee must start with the letter specified in the link list A-Z that were clicked.

now my problem is, the links are called to the same page and does not contain its own php file. from the site that was recommended on me to study, i saw that each linked have its own php file thus the only difference is the location on the class=current example:

if your on A.php

    <ol id="toc">
<li class="current"><a href="A.php"><span>A</span></a></li>         
<li><a href="B.php"><span>B</span></a></li>
</ol>

the link in that page contains the class=current but the other li tags does not, else when clicked on a different link like for example on B.php

<ol id="toc">
<li><a href="A.php"><span>A</span></a></li>         
<li class="current"><a href="B.php"><span>B</span></a></li>
</ol>

the class="current" is in link B.

but mine is called in the same page by inserting ?namelist=a in each link. if i put class="current" on every li link, i would be able to get what i want which is making it able to see your current page. does anyone here knows how?? thanks for those who will reply :)

MisaChan


This function will loop through a to z and check if the current page is index.php?namelist=a or b,c ect determining where to place the class="current"

function toc_menu($current){
    $return ='<ol id="toc">
                <li>&nbsp;&nbsp;&nbsp;</li>'."\n";
    $return .= ($current=='') ? '<li class="current"><a href="index.php"><span>#</span></a></li>'."\n" : '<li><a href="index.php"><span>#</span></a></li>'."\n";
    foreach(range('a','z') as $link){
        $return .= ($current==$link) ? '<li class="current"><a href="index.php?namelist='.$link.'"><span>'.strtoupper($link).'</span></a></li>'."\n" : '<li><a href="index.php?namelist='.$link.'"><span>'.strtoupper($link).'</span></a></li>'."\n";
    }
    $return .="</ol>\n";
    return $return;
}

//echo where you want the menu
echo toc_menu(strtolower($_REQUEST['namelist']));

//or hold it in a variable to display later on
$tocmenu = toc_menu(strtolower($_REQUEST['namelist']));

//outputs this is E was clicked

   <ol id="toc">
                <li>&nbsp;&nbsp;&nbsp;</li>
<li><a href="index.php"><span>#</span></a></li>
<li><a href="index.php?namelist=a"><span>A</span></a></li>
<li><a href="index.php?namelist=b"><span>B</span></a></li>
<li><a href="index.php?namelist=c"><span>C</span></a></li>
<li><a href="index.php?namelist=d"><span>D</span></a></li>
<li class="current"><a href="index.php?namelist=e"><span>E</span></a></li>
<li><a href="index.php?namelist=f"><span>F</span></a></li>

<li><a href="index.php?namelist=g"><span>G</span></a></li>
<li><a href="index.php?namelist=h"><span>H</span></a></li>
<li><a href="index.php?namelist=i"><span>I</span></a></li>
<li><a href="index.php?namelist=j"><span>J</span></a></li>
<li><a href="index.php?namelist=k"><span>K</span></a></li>
<li><a href="index.php?namelist=l"><span>L</span></a></li>
<li><a href="index.php?namelist=m"><span>M</span></a></li>
<li><a href="index.php?namelist=n"><span>N</span></a></li>
<li><a href="index.php?namelist=o"><span>O</span></a></li>

<li><a href="index.php?namelist=p"><span>P</span></a></li>
<li><a href="index.php?namelist=q"><span>Q</span></a></li>
<li><a href="index.php?namelist=r"><span>R</span></a></li>
<li><a href="index.php?namelist=s"><span>S</span></a></li>
<li><a href="index.php?namelist=t"><span>T</span></a></li>
<li><a href="index.php?namelist=u"><span>U</span></a></li>
<li><a href="index.php?namelist=v"><span>V</span></a></li>
<li><a href="index.php?namelist=w"><span>W</span></a></li>
<li><a href="index.php?namelist=x"><span>X</span></a></li>

<li><a href="index.php?namelist=y"><span>Y</span></a></li>
<li><a href="index.php?namelist=z"><span>Z</span></a></li>
</ol>


From what I understand, you want a different color of the link on the current page. For e.g. if someone goes to index.php?namelist=a, the color for link A should be different than others. If this is the case, then just add a check for $_REQUEST['namelist'] while adding the class and you should be okay.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜