NarcosZTK_10
NarcosZTK_10

Reputation: 147

How concatenate a PHP variable into a HTML link?

i need to concatenate this variable $idCantiere into a href attribute

<a class="btn btn-primary" href="../../../paginaIniziale/sceltaModificaAffidatario.php?idCantiere='.$idCantiere.'">Continua -></a>   `

In other words, I need that when I press the "Continua->" button, I will be redirected to the HREF page but with the addition, at the end of the link, of the "idCantiere"

Upvotes: 1

Views: 3042

Answers (2)

Willem van der Veen
Willem van der Veen

Reputation: 36680

Try the following:

<a class="btn btn-primary" href="../../../paginaIniziale/sceltaModificaAffidatario.php?idCantiere=<?php echo $idCantiere ?>Continua -></a>

What this does is the following:

  1. opens <?php tags so we can write php.
  2. echo your variable in the html template
  3. Close the php by ?>

When you use echo in php it will output the value of a variable to the actual HTML file that will be produced. Thus you use echo when you need to output something dynamic into the html.

Upvotes: 6

McNulty
McNulty

Reputation: 31

Here are two possible solutions:

https://www.tehplayground.com/rpPcUnram5TAxdAs

Have fun!

edit: sorry for that here is the code:

No 1:

<?php
$idCantiere = 123;
print '<a class="btn btn-primary" href="../../../paginaIniziale/sceltaModificaAffidatario.php?idCantiere='.$idCantiere.'">Continua -></a>';
?>

No 2:

<?php
$idCantiere = 123;
?>
....
<a class="btn btn-primary" href="../../../paginaIniziale/sceltaModificaAffidatario.php?idCantiere=<?php print $idCantiere; ?>">Continua -></a>

Upvotes: 0

Related Questions