【发布时间】:2016-08-03 21:46:10
【问题描述】:
大家好,
目前我正在制作一个具有以下功能的网页:
当管理员打开页面时,管理员将看到一个表格,其中包含来自数据库的这些信息:
此页面的作用是显示每个用户在数据库中有多少个视频,当管理员单击所需的用户 ID 时,应该会打开一个包含该特定用户 ID 的视频的新页面。 “完成”按钮是当管理员删除视频后返回主页。
现在,我所做的是为从数据库中获取的用户 ID 值分配了一个 href 链接。问题是,我不知道如何使用 href 将选定的值/字符串传递到下一页。我已经尝试过使用 Session,但最终在 WHILE 循环中处理了最后一个变量,而不是获取单击的用户 ID。下面是我所做的 php 代码。谁能给我一些关于如何使用 href 将点击的用户 ID 从一个页面传递到另一个页面的提示,或者还有其他方法可以做到这一点吗? code= click here
ps:正如大家所见,我的 php 编码需要一些认真的改进。但我仍在努力通过做这些类型的练习来提高自己。
<?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"> </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
?>
【问题讨论】:
-
包括所有相关代码到 OP
-
我已经为文本中的代码插入了一个超链接:标记为“代码=点击此处”
-
在这里贴代码,或者粘贴到其他地方,截图是一种不好的分享方式。
-
好的。我的错。不知道截图的那部分。
标签: javascript php jquery html mysql