doutui8842 2016-05-16 23: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 00: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条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部