Ricardo Pires Ricardo Pires - 1 year ago 70
HTML Question

Passing a variable value from one page to another in php

i have this code that will show any product containing the word adidas in my database at a specified table. So the next thing is to link the code of the product to the certain product and then have it link to another page so that it will populate automatically recurring that product code.
Ive tried the session method but it only gives me the last code , like this , if theres is this codes: cha3 cha2 cha1, it will give me cha1 no matter what ive clicked the other page.What i wanted to do is if you click product with the code cha1 it will populate the produto.php with the details of cha1.Sorry if i didnt make me understand , ill post here the snippet of code to give some idea , its "clean" because i tried a lot of methods and until now nothing worked.


$sql="SELECT * FROM produto WHERE nome_produto LIKE '%ADIDAS%'";
<div class="row shop_box-top">

while (odbc_fetch_row($resultado))

$codigo = odbc_result($resultado,1);
$nome = odbc_result($resultado,2);
$preco = odbc_result($resultado,4);
$foto1 = odbc_result($resultado,9);


<div class="col-md-3 shop_box"> <a href="produto.php" >
<img src=" <?php echo $foto1;?>" class="img-responsive" alt=""/>
<span class="new-box">
<span class="new-label">Novo</span>
<?php $codigo ?>
<div class="shop_desc">
<h3><a href="produto.php> <?php echo $nome;?> </a></h3>

<span class="actual"><?php echo $preco; ?></span><br>



<?php }?>

Answer Source

If I understand correctly, I think you can use GET parameters in your links to pass whatever information you want on your other page.

<a href="produto.php?code=<?php echo $variable_with_the_code; ?>">
    <?php echo $nome;?>

You can add more GET params if you need. On the other page you can access these values like $_GET['code'].

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download