doutuan6158 2016-04-13 02:33
浏览 21
已采纳

从一个页面到另一个页面获取单击的href变量

Greeting everyone,

Currently i'm making a webpage that has the following functions:

When the administrator opens the page, admin will be seeing a form filled with these information from a database: enter image description here

What this page does is that it shows how many video's each user has in the database and when the admin clicks on the desired user ID, a new page should open with the video's of that specific user ID. The " DONE" button is to return to the main page when the admin is done deleting video's.

Now, what I have done is that I've assigned an href link to the userID values that is being fetched from Database. The problem is that, I have no clue how to pass the selected value/string to the next page with href. I've tried with Session, but ended up getting the last variable processed in the WHILE loop instead of getting the clicked UserID. Below follows my php code of what I've done. Can anyone give me some tips on how to pass the clicked userID from one page to another with href, or is there another way to do this? code= click here

ps: As everyone can see, my php coding needs some serious improvement. But i'm still trying to improve by doing these types of exercises.

<?php

include_once ("includes/db_connection.php");
$sql = "SELECT Users_UserID, count(Users_UserID) AS total FROM video GROUP     BY Users_UserID";
 $sql2="SELECT UserID, FirstName, LastName FROM users";
$result = $connection->query($sql);
$result2 = $connection->query($sql2);

?>

<table width="400" border="0" cellspacing="1" cellpadding="0">
    <tr>
        <td><form name="deleteSingleVideo" method="post" action="">
                <table width="400" border="0" cellpadding="3"     cellspacing="1" bgcolor="#CCCCCC">
                    <tr>
                        <td bgcolor="#FFFFFF">&nbsp;</td>
                        <td colspan="4" bgcolor="#FFFFFF"><strong>Delete     user video</strong> </td>
                </tr>
                <tr>
                    <td align="center" bgcolor="#FFFFFF">#</td>
                    <td align="center" bgcolor="#FFFFFF"><strong>First Name</strong></td>
                    <td align="center" bgcolor="#FFFFFF"><strong>Last Name</strong></td>
                    <td align="center" bgcolor="#FFFFFF"><strong>User ID</strong></td>
                    <td align="center" bgcolor="#FFFFFF"><strong>Amount of videos</strong></td>
                    </tr>
                <?php
                session_start();
                if ($result->num_rows > 0) {
                    while (($row=$result->fetch_assoc())&& ($row2=$result2->fetch_assoc()) ) {
                        ?>

                        <tr>
                            <td align="center" bgcolor="#FFFFFF"></td>
                            <td bgcolor="#FFFFFF"><center><?php echo $row2['FirstName']; ?></center></td>
                            <td bgcolor="#FFFFFF"><?php echo $row2['LastName']; ?></td>
                            <td bgcolor="#FFFFFF"><center><a href="DeleteVideo.php" target="_blank"><?php echo $row['Users_UserID'];
                                    $_SESSION['id']=$row['id'] ?></center></td>
                            <td bgcolor="#FFFFFF"><center><?php echo $row['total'];?></a></center></td>
                        </tr>

                        <?php
                    }
                }
                ?>

                <tr>
                        <td colspan="5" align="center" bgcolor="#FFFFFF"><input     name="Done" type="submit" id="Done" value="Done" </td>
                    </tr>

                    <?php

                    $connection->close();
                    if(isset($_POST['Done'])){

                        header( "Location: Home.php" );
                    }
                    ?>

                </table>
            </form>
        </td>
    </tr>
</table>
<?php

?>
  • 写回答

3条回答 默认 最新

  • dongqi4085 2016-04-13 02:54
    关注

    this is not a good use of session

    use get method to send such data :

    1. append the id to href url --->href="<?php echo "DeleteVideo.php?id="$row['id'] ?>";
    2. get data in the next page by accessing global variable ---> $_GET['id']
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制