dongluxin6711 2016-06-02 15:20
浏览 222
已采纳

在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.

I've tried the session method but it only gives me the last code. If there is this code: cha3 cha2 cha1, it will give me cha1 no matter what I've clicked on 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 you don't understand. I'll post s snippet of code to give some idea. It's "clean" because I tried a lot of methods and until now nothing worked.

  <?php

        $ligaBD=odbc_connect('basededadospap','','');
        $sql="SELECT * FROM produto WHERE nome_produto LIKE '%ADIDAS%'";
        $resultado=odbc_exec($ligaBD,$sql);
        ?>
        <div class="row shop_box-top">

        <?php
        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>
                </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>

                </div>

            </a></div>


        <?php }?>
  • 写回答

1条回答 默认 最新

  • douya2433 2016-06-02 15:32
    关注

    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;?>
    </a>
    

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵