Php 如何查询特定相册中的照片

Php 如何查询特定相册中的照片,php,mysql,mysqli,Php,Mysql,Mysqli,PhotosInAlbums表格 //Gets album id from form $album_id = $_GET['album_id']; //Returns all photo_id for photos in that album $result2 = $mysqli->query("SELECT photo_id FROM PhotosInAlbum WHERE album_id = $album_id"); //RETURNS FALSE WHY? //Returns

PhotosInAlbums表格

//Gets album id from form
$album_id = $_GET['album_id'];

//Returns all photo_id for photos in that album
$result2 = $mysqli->query("SELECT photo_id FROM PhotosInAlbum WHERE album_id = $album_id"); //RETURNS FALSE WHY?

//Returns all the rows where the photo_id matches Photos tables' id
$result = $mysqli->query("SELECT * FROM Photos WHERE id = $result2");

    while ( $row = $result->fetch_assoc()) {
 print('<div class = "cell">
                <div class = "photo_container" >

        $title = $row[ 'title'];
        $file_path = $row[ 'file_path' ];

        print('<img class = "photo_image" src = "'.$file_path.'" alt = "default album" width = "300"/>
        print('<div class = "photo_title">'.$title.' ('.$credit.')</div>');               
        print('  </div>
            </div>');
    }

照片表

使用
$mysqli->query()
,我想返回照片表中的照片id与具有相同相册id的PhotoInAlbums中的照片id匹配的所有行。因此,本质上,返回相同相册中照片的信息(id、标题、创建日期、修改日期、文件路径),以便我可以在表中显示这些照片。我该怎么做?另外,我对
$results2
的查询返回false,我不知道为什么

代码

//Gets album id from form
$album_id = $_GET['album_id'];

//Returns all photo_id for photos in that album
$result2 = $mysqli->query("SELECT photo_id FROM PhotosInAlbum WHERE album_id = $album_id"); //RETURNS FALSE WHY?

//Returns all the rows where the photo_id matches Photos tables' id
$result = $mysqli->query("SELECT * FROM Photos WHERE id = $result2");

    while ( $row = $result->fetch_assoc()) {
 print('<div class = "cell">
                <div class = "photo_container" >

        $title = $row[ 'title'];
        $file_path = $row[ 'file_path' ];

        print('<img class = "photo_image" src = "'.$file_path.'" alt = "default album" width = "300"/>
        print('<div class = "photo_title">'.$title.' ('.$credit.')</div>');               
        print('  </div>
            </div>');
    }
//从表单获取相册id
$album\u id=$\u GET['album\u id'];
//返回该相册中照片的所有照片id
$result2=$mysqli->query(“从PhotosInAlbum中选择照片id,其中相册id=$album_id”)//返回错误为什么?
//返回照片id与照片表id匹配的所有行
$result=$mysqli->query(“从id=$result2的照片中选择*);
而($row=$result->fetch_assoc()){
打印('
$title=$row['title'];
$file_path=$row['file_path'];
打印('
打印(“.$title.”(“.$credit.”)字样);
打印('
');
}