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

php不会回显内部联接查询的结果,php,mysql,inner-join,Php,Mysql,Inner Join,我在网站上到处寻找类似的问题的解决方案,似乎没有人能解决我的问题。我有两张桌子;“好友列表”和“用户”。我试图使用“friendlist”中的“FriendID”从“users”表中检索信息。在while($row=mysqli_fetch_array($result)){}循环之前,一切都正常,然后就不会打印其他内容 我的代码如下: $query = "SELECT friendlist.FriendID, users.Name, users.Surname, users.Picture

我在网站上到处寻找类似的问题的解决方案,似乎没有人能解决我的问题。我有两张桌子;“好友列表”和“用户”。我试图使用“friendlist”中的“FriendID”从“users”表中检索信息。在
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>";
}
$query=“选择friendlist.FriendID,users.Name,users.Name,users.users,users.Picture
来自朋友名单
内部加入用户
在friendlist.FriendID=users.Id上
其中friendlist.UserId=“$id.”;
$result=mysqli\u查询($con,$query);
如果(!$result){
echo“
您当前没有任何朋友。请单击“查找朋友”按钮查找朋友”; }否则{ echo“
这是您所有朋友的列表:
”; 回声“; while($row=mysqli\u fetch\u数组($result)){ 回声“; echo“Pro-Pic:”; echo“Name:”.$row['Name']。”; 呼应“姓氏:.$row[“姓氏]”; 回声“; 回声“; 回声“; 回声“; 回声“; } 回声“; }
浏览器上不显示任何内容。只有第4级标题文本:“这里是您所有朋友的列表”显示。但在那之后,它是一片空白。

我已经检查了mySql上的sql查询,它运行得非常好。我不知道怎么了。任何帮助都将不胜感激。谢谢

问题出在您的SQL查询上。 您没有将friendlist.UserId放在所选部件上。 这就是为什么where子句看不到在哪里比较它

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

您的代码是正确的,但您只错过了$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>";
    }
//将$id初始化为。
$id=$\u请求['id'];
$query=“选择friendlist.FriendID,users.Name,users.姓氏,users.Picture
来自朋友名单
内部加入用户
在friendlist.FriendID=users.Id上
其中friendlist.UserId=“$id.”;
$result=mysqli\u查询($con,$query);
如果(!$result){
echo“
您当前没有任何朋友。请单击“查找朋友”按钮查找朋友”; }否则{ echo“
这是您所有朋友的列表:
”; 回声“; while($row=mysqli\u fetch\u数组($result)){ 回声“; echo“Pro-Pic:”; echo“Name:”.$row['Name']。”; 呼应“姓氏:.$row[“姓氏]”; 回声“; 回声“; 回声“; 回声“; 回声“; } 回声“; }
echo mysqli\u num\u行($result);并检查它们的行数?您很可能会使用SQL注入,需要尽快修复此问题,除非您希望任何人都能够显示整个系统中的所有用户。使用准备好的语句和绑定变量。将
mysql\u
神奇地更改为
mysqli\u
并不能解决此问题。或者先在phpmyadmin中运行查询,检查它们是否有内容。@SureshKamrushi结果是0!但我不明白怎么回事,因为正如Christian Mark所建议的,我在phpmyadmin上运行了查询,结果返回了两行结果。你确定连接到了正确的数据库吗?和它有很好的联系吗?你检查过php错误吗?我试过了,但不起作用:(如果我试图将friendlist.UserId用作搜索条件,我认为选择friendlist.UserId没有意义……如果你知道我的意思,我刚刚意识到我的错误是什么,太愚蠢了!!>\uuu<$id还没有设置值。在我设置会话的脚本开头:
session\u start();$id=$\u session['id']
我以为我已经为$id赋值了。我不得不再次赋值
$id=$\u SESSION
(不知道为什么会这样)现在它可以工作了。谢谢你的建议,并对给你带来的不便表示歉意…P.既然代码不是问题,我需要删除这个问题吗?