gpt4 book ai didi

php 不会回显内部连接查询的结果

转载 作者:行者123 更新时间:2023-11-30 23:10:02 25 4
gpt4 key购买 nike

我在网站上四处寻找类似问题的解决方案,但似乎没有解决我遇到的问题。我有两张 table ; “好友列表”和“用户”。我正在尝试使用“好友列表”中的“FriendID”从“用户”表中检索信息。一切正常,直到 while($row = mysqli_fetch_array($result)){} 循环然后没有其他打印。

我的代码如下:

$query = "SELECT friendlist.FriendID, users.Name, users.Surname, users.Picture 
FROM friendlist
INNER JOIN users
ON friendlist.FriendID = users.Id
WHERE friendlist.UserId ='".$id."'";
$result = mysqli_query($con, $query);

if(!$result){
echo "<br/><h4>You currently do not have any friends. Please click the Find Friends button to find a friend</h4>";
}else{
echo "<center><br/>Here is a list of all your friends:<br/>";
echo "<table>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>Pro Pic: <img style='width:200px; height:200px' alt='No Profile Picture' src='uploads/" .$row['Picture']. "' /></td>";
echo "<td>Name :" .$row['Name']. "</td>";
echo "<td>Surname :" .$row['Surname']. "</td>";
echo "<td><form method='post' action='viewFriend.php'>";
echo "<input type='hidden' name='friendId' value='".$row['FriendID']."'/>";
echo "<input type='submit' name='View' value='View Profile'/>";
echo "</form></td>";
echo "</tr>";
}
echo "</table></center>";
}

浏览器上没有任何显示。仅显示 4 级标题文本:“这是您所有 friend 的列表”。但在那之后是一片空白。
我检查了 mySql 上的 sql 查询,它工作得很好。我不知道出了什么问题。任何帮助都感激不尽。谢谢

最佳答案

您的代码是正确的,但您只错过了 $id 变量的声明。像下面这样使用。

//initialize  the $id as.

$id = $_REQUEST['id'];

$query = "SELECT friendlist.FriendID, users.Name, users.Surname, users.Picture
FROM friendlist
INNER JOIN users
ON friendlist.FriendID = users.Id
WHERE friendlist.UserId ='".$id."'";
$result = mysqli_query($con, $query);

if(!$result){
echo "<br/><h4>You currently do not have any friends. Please click the Find Friends button to find a friend</h4>";
}else{
echo "<center><br/>Here is a list of all your friends:<br/>";
echo "<table>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>Pro Pic: <img style='width:200px; height:200px' alt='No Profile Picture' src='uploads/" .$row['Picture']. "' /></td>";
echo "<td>Name :" .$row['Name']. "</td>";
echo "<td>Surname :" .$row['Surname']. "</td>";
echo "<td><form method='post' action='viewFriend.php'>";
echo "<input type='hidden' name='friendId' value='".$row['FriendID']."'/>";
echo "<input type='submit' name='View' value='View Profile'/>";
echo "</form></td>";
echo "</tr>";
}
echo "</table></center>";
}

关于php 不会回显内部连接查询的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20237930/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com