开发者

suggest proper conditional statement to fade tabs with CSS via PHP

开发者 https://www.devze.com 2023-02-25 06:14 出处:网络
I want to change the class of two tabs via PHP, but I am stuck in basic condition. here is my code: CSS

I want to change the class of two tabs via PHP, but I am stuck in basic condition. here is my code:

CSS

.myinfo { background-color:black }
.deactive { background-color : white }  

HTML

<li class="myinfo <?=$deact?>">
    <a href="myaccount.php?<?=$qry_str?>" >My Info</a>
</li>
<li class="myinfo <?=$deact?>">
    <a href="myaccount.php?mycontacts&<?=$qry_str?>">My Contacts</a>
</li>

What I need is

if $_GET['mycontacts'] is active

then My Info link should have class deactive

otherwise My Contacs link should have class deactive

I tried this:

if (isset($_GET['myco开发者_如何学Gontacts'])){
    $deact ='deactive';
}

But it did not succeed. Please help to write this condition (I think a one line ternary condition could work).


Try this:

<li class="myinfo <?php echo ($_GET['mycontacts'] === 'active' ? 'deactive' : '') ?>">
  <a href="myaccount.php?<?=$qry_str?>" >My Info</a>
</li>
<li class="myinfo <?php echo ($_GET['mycontacts'] !== 'active' ? 'deactive' : '') ?>">
  <a href="myaccount.php?mycontacts&<?=$qry_str?>">My Contacts</a>
</li>

By the way I hate php short tags! Personal preference...

0

精彩评论

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