dsrruefh12970 2015-11-02 19:06
浏览 52
已采纳

如何在php中制作一个带有变量的可点击图像到另一个页面?

My question is pretty simple. I tried doing some research into this but I never got it working with images.

I want to have a clickable image so when a user clicks on that image, it carries over some type of variable (ID) to another php page, so I can know which image that user clicked on and give the result.

My current code is this:

    echo '<a href="viewer.php"><img  src=' . $covers->src . 'height="300" width="190" value=' . $test . ' name="view" /></a>';

I tried doing this on my second php page:

$var_value = $_GET['view];
echo $var_value;

but I get undefined error on line 1.

  • 写回答

4条回答 默认 最新

  • dousuohe5882 2015-11-02 19:14
    关注

    You try to fetch a parameter called view with $_GET. Simply add a parameter to your link called view and then its value.

    echo '<a href="viewer.php?view=theValueIWantToBringAlong"><img  src="' . $covers->src . '" height="300" width="190" name="view" /></a>';
    

    In this example, using

    echo $_GET['view'];
    

    when at viewer.php will print "theValueIWantToBringAlong".

    If your value is is stored in a variable, then do like this:

    $myValue = 'theValueIWantToBringAlong';
    echo '<a href="viewer.php?view='.$myValue.'"><img  src="' . $covers->src . '" height="300" width="190" name="view" /></a>';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算