hyperlink click condition

Asked

Viewed 46 times

1

I want that when you click on the hyperlink for the second time another code is executed.

<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 click once do the ASC if it is the second time DESC, and so on.

  • Can you explain better what you want to do? Since this doesn’t make much sense... Want to do this on the client or server side? Explain a little of the context pf.

  • I have a link. Quando clico a primeira vez, quero que execute este codigo array_multisort( $affiche_ord, SORT_ASC, $affiche_tab ); e quando voltar a clicar executar array_multisort( $affiche_ord, SORT_DESC, $affiche_tab );

  • Okay, and you want the click to be on the client side sort in PHP/server... why not do this in Javascript? Want to reload the page or do this via AJAX?

  • is a link that reloads the page. Yes from the client side.

1 answer

1

You can do it this way by switching between one parameter and another, capturing the variable ordem with $_GET and applying in 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 parameter ordem is empty, will be included in the link the value ?ordem=SORT_ASC, and then you alternate with ?ordem=SORT_DESC as the link is being clicked.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.