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条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划