condition hyperlink click

1

I want you to click on the hyperlink for the second time to execute another code.

<a href=?ordem=nom>$lib_nom</a>


//ordena dados do array ASC
array_multisort( $affiche_ord, SORT_ASC, $affiche_tab );

//ordena dados do array DESC
array_multisort( $affiche_ord, SORT_DESC, $affiche_tab );

If you click once make the ASC if it is the second time DESC, and so on.

    
asked by anonymous 01.12.2014 / 23:59

1 answer

1

You can do this by switching between one parameter and another by capturing the variable ordem with $_GET and applying to the function according to the parameter sent by the link:

<?php
$ordem = $_GET['ordem'];
$nova_ordem = empty($ordem) || $ordem == 'SORT_DESC' ? 'SORT_ASC' : 'SORT_DESC';

echo '<a href="?ordem='.$nova_ordem.'">$lib_nom</a>';

array_multisort( $affiche_ord, $ordem, $affiche_tab );
?>

If the ordem parameter is empty, the ?ordem=SORT_ASC value will be included in the link, and then it will alternate with ?ordem=SORT_DESC as the link is clicked.

    
03.01.2018 / 05:17