How do I change the value of a PHP variable by clicking a link?

2

For example, I have a variable called:

$idEmpreendimento = "1";

I would like, by clicking on a particular link, I could change this value to 2. Is it possible?

--------------------------- EDIT ~ Solution

For those who want the solution, I was able to solve it as follows:

I changed the variable to:

$idEmpreendimento = (isset($_GET["id"])) ? $_GET["id"] : "1";

And in the links, I would put, for example

<a href="?id=1">Link</a>

In this specific case, I ended up pulling the id number directly from the database with a:

echo "<li><a href='?id=" . $Listagem['id'] . "#imoveis" . "'>" . $Listagem['nome'] . "</a></li>";

Anyone who has a similar question and wants to ask, feel free.

    
asked by anonymous 14.10.2014 / 18:00

2 answers

1

You can use $_GET as described in the comments.

Mount the link

<a href="link-para-pagina.php?id=2">Link</a>

After the ? in the link, the $_GET variables are declared, if you want several, use & to separate them, like this: link-para-pagina.php?id=2&grupo=7 .

And receive the variables:

$idEmpreendimento = (isset($_GET['id']) ? $_GET['id'] : '1');

The expression means that if the variable $_GET['id'] was declared, then the variable $idEmpreendimento will receive its value, otherwise it will receive the default value 1 .     

14.10.2014 / 20:34
1

A "Simple" form would be, Use Ajax and $ _SESSION. You create a session and each click sends a message via ajax to a page that updates the session value.

$_SESSION['contador'] += 1;

Then retrieve the session value also via ajax. And then switch to PHP when you need it.

    
14.10.2014 / 18:30