There are three references to sorting (by status, email address, name), by default - all in ascending order. How to effectively make it so that when you are on any page with the selected sorting (be it /sort/status_desc/ or /sort/status_asc/) , the corresponding button changed its link to the opposite , i.e. to sort by decrease?

I am on /sort/status_desc/ - the link changes to /sort/status_asc/ .

This is what I did, but I consider this code ineffective, because it takes too much space if you screw it to each <div> link with classes:

 Сортировать по: <?php if($sort == 'status_asc'): ?> <a href="/sort/status_desc/">Статусу</a> <a href="/sort/email_asc/">Эл. Почте</a> <a href="/sort/name_asc/">Имени</a> <?php endif;?> <?php if($sort == 'email_asc'): ?> <a href="/sort/status_asc/">Статусу</a> <a href="/sort/email_desc/">Статусу</a> <a href="/sort/name_asc/">Имени</a> <?php endif;?> <?php if($sort == 'name_asc'): ?> <a href="/sort/status_asc/">Статусу</a> <a href="/sort/email_asc/">Эл. Почте</a> <a href="/sort/name_desc/">Статусу</a> <?php endif;?> // еще 3 проверки на сортировки убыванием (sort_desc) <?php if(!isset($sort)): ?> <a href="/sort/status_asc/">Статусу</a> <a href="/sort/email_asc/">Эл. Почте</a> <a href="/sort/name_asc/">Имени</a> <?php endif;?> 

    1 answer 1

    Um, rendering optimization? Pages slow down from one and this is JS. from pkhp brakes only on the server :)

    And since the code is not very effective, too much? Php ...

    Generally make a gene from an array of chtoli ...

     например $array = array( array('url'=>'?home=ffff', 'title'=>4444), array('url'=>'?sss=eee', 'title'=>5657, 'header'=>ttt) ) foreach($array as $v){ ......... }