在SQL中的Inner Join之后获取值

时间:2017-09-23 17:33:42

标签: php mysql join

我有以下表格:

rooms - id, room_name, room_type
room_type - id, type_name.

此表的示例:

Rooms- id=1 , room_name = "101" , room_type = "1"
room_type - id=1 , type_name = "Deluxe".

现在我正在尝试获取此表格我希望它显示房间类型名称而不是room_type id。

与上述情况一样,我希望输出如下:

1,101,Deluxe.

我尝试过这次加入,但失败了:

SELECT * from rooms r INNER JOIN room_type t on t.id = r.room_type

我收到以下错误:

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given 

请帮忙

更新

这是php获取代码:

$getquery =mysqli_query($connection,"SELECT * from rooms r INNER JOIN room_type t on t.id = r.room_type");

while($row=mysqli_fetch_array($getquery)){

    echo "<tr>";
    echo "<td> </td>";
    echo "<td>" . $row['room'];
    echo "<td>" . $row['room_type'];

1 个答案:

答案 0 :(得分:0)

您的查询似乎失败并返回false值。下面是示例/虚拟代码

$sql = "SELECT * from rooms r INNER JOIN room_type t on t.id = r.room_type";
$result = myqli_query($connection,$sql);
while($r = mysqli_fetch_array($result)
{
    /// your code here
}