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
then My Info link should have class$_GET['mycontacts']
is activedeactive
otherwise My Contacs link should have classdeactive
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...
精彩评论