【发布时间】:2019-07-27 21:59:38
【问题描述】:
我正在开发一个项目,其中我有一个管理员和用户,所以在管理面板中我有一个表格,其中所有视频和所有用户都用复选框列出。
在表格中,我有两列视频和用户。在视频列中,列出了所有视频,在用户列中,还有另一个名为“选择用户”的表,其中列出了所有用户,每个视频都有一个复选框。
所以问题是当管理员选择用户的复选框时,我想知道他为哪个视频选择了用户,以便特定视频只显示给用户面板中的选定用户。
用户表的图片链接 链接:https://ibb.co/t25kppy
希望大家理解我的问题
我可以从复选框中获取所选用户的姓名,但不知道如何获取所选用户的视频
<?php
require_once 'Header.php';
require_once 'Includes/DB.php';
$query = 'SELECT * FROM `videos`;';
$query2 = 'SELECT `FullName` FROM `users`;';
$result = mysqli_query($conn, $query);
$result2 = mysqli_query($conn, $query2);
$checkResult = mysqli_num_rows($result);
$checkResult2 = mysqli_num_rows($result2);
while ($row2 = mysqli_fetch_assoc($result2)) {
$data[] = $row2['FullName'];
?>
<main>
<div class="container">
<table class="table">
<thead>
<tr>
<th scope="col"><h4 align="center">Videos</h4></th>
<th scope="col"><h4 align="center">Users</h4></th>
</tr>
</thead>
<tbody>
<?php
if ($checkResult > 0 && $checkResult2 > 0)
{
while ($row = mysqli_fetch_assoc($result))
{
echo '
<tr>
<form action="Select_Users.php" method="post">
<td align="center" scope="row"> <iframe width="200" height="200" src="https://www.youtube.com/embed/' . $row['youtube_video_id'] . '"frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>
</td>
<td>
<table class="table">
<thead>
<th scope="col"><h4 align="left">Select Users</h4></th>
</thead>
<tbody>
<tr>
<td>';
for ($i = 0; $i < count($data); $i++)
{
echo '<div><label><input type="checkbox" name="selectedUsers[]" value="' . $data[$i] . ' ">' . $data[$i] . '</label></div> <br><br>';
}
echo'
<button type="submit" name="Submit"> Submit</button>
</td>
</form>
</tr>
</tbody>
</table>
</td>';
}
}
else
{
echo 'no result fount in database';
}
?>
</tbody>
</table>
</form>
</div>
<?php
if (isset($_POST['Submit']))
{
if (!empty($_POST['selectedUsers']))
{
foreach ($_POST['selectedUsers'] as $selectedUsers)
{
echo '<h1>'.$row['youtube_video_id'].'</h1>';
echo '<h1>'.$selectedUsers.'</h1>';
}
}
else
{
echo '<h1>No value found</h1>' ;
}
}
?>
【问题讨论】: