doutui8842 2016-05-17 07:57
浏览 27
已采纳

在另一个php文件中获取html标记的id

I have a database table Library and I have fetched image src from the table and gave the name of the image tag as id from the table as name=".$idRow.".

So what i want to do is that when the user clicks on an image id of the image from the table should be passed in the name of that image tag, which is successfully done.

But when i pass that id through a variable using session ($_SESSION['sessionBookId']=$idRow;) to another PHP file only the last id of the book is passed through that variable.

I want to pass the id of the image clicked but only the last id is passed. Is there a solution?

<?php    
    $sqlSelectImage = "SELECT * FROM Library WHERE 1";
    $queryExec = mysqli_query($link, $sqlSelectImage);

    while ($rs = mysqli_fetch_object($queryExec)) {
        $idRow=stripcslashes($rs->id);

?>
<tr>
    //image tag
    <td align="center">
    <?php 
        echo "<a href=".'book-view.php'." name=".$idRow.">";
        $_SESSION['sessionBookId']=$idRow;
    ?>
        <img src="<?php echo stripcslashes($rs->book_url); ?>" alt="" width="100" height="100" />
    <?php echo"</a>" ?>
    </td>
    <td align="center">
        <form action="" method="POST"><input type="submit" value="buy" name="bookView"/>
        </form>
    </td>
</tr>

<?php
    if (isset($_POST['bookView'])) {
        header("Location:book-view.php");
        exit();
    }
?>
  • 写回答

2条回答 默认 最新

  • douhuilin1152 2016-05-17 08:07
    关注

    Use this code

    <td align="center"><?php echo "<a href=\"book-view.php?id=$idRow\">";?><img src="<?php echo stripcslashes($rs->book_url); ?>" alt="" width="100" height="100" /></a></td>
    

    in the book-view.php you can access to passes value with

    $_GET['id']
    

    in the way you can pass variable with GET

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 vc6.0中想运行代码的时候总是提示无法打开文件是怎么回事
  • ¥25 关于##爬虫##的问题,如何解决?:
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题