在图像所示的表中,我想显示用户通过单击“保存”添加的名称,但是如果两者是彼此添加的,例如如果Alice添加了Bob并且Bob已添加了Alice,则必须指明它(一些符号,另一种颜色)。 如何为此创建数据库表,因为无法验证用户Alice是否添加了Bob,如何确认Bob也添加了Alice以便在下表中显示它们。 this is the image what I want to get
这是我的代码,index.php
<form action="save.php" method="post">
<div class="text-center" id='input_tag'>
<input type="text" name="name" id= 'input'>
<input type="submit" name="submit" class="btn btn-dark " id = "button" value="Save">
</div>
</form>
<div class="container">
<div class="row">
<div class="col-md-4">
<table width="100" class="table" id = 'tb'>
<?php
$connect = mysqli_connect('localhost','root','root','user');
$query = "SELECT name from userdata order by id DESC";
$run = mysqli_query($connect,$query);
while($row = mysqli_fetch_array($run))
{
echo "<tr>";
echo "<td class= 'active'>".$row['name']."<td>";
echo "</tr>";
}
?>
</table>
</div>
</div>
</div>
这是save.php
$connect = mysqli_connect('localhost', 'root' ,'root' ,'user');
if($connect){
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$query = "INSERT INTO `userdata`(`name`) values ('$name')";
if(mysqli_query($connect,$query)){
header('location:index.php');
}
}
}
else{
echo "not connected";
}
这是我数据库中的表 table in the DB