dongzhi1822 2013-11-27 09:04
浏览 13

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

I've looked around the site for similar problems with solutions and non seem to fix the problem I have. I have two tables; "friendlist" and "users". I'm trying to use the "FriendID" from "friendlist" to retrieve information from the "users" table. Everything works fine up until the while($row = mysqli_fetch_array($result)){} loop then nothing else prints.

My code is as follows:

$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>";
}

Nothing is displayed on the browser. Only the level 4 heading text: "Here is a list of all your friends" shows. But after that its empty space.
I've checked the sql query on mySql and it works perfectly fine. I have no idea what's wrong. Any help will be much appreciated. Thanks

  • 写回答

2条回答 默认 最新

  • doucu9677 2013-11-27 10:13
    关注

    The problem is on your SQL Query. You did not put friendlist.UserId on the select part. That's why the where clause do not see where to compare it.

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

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题