在透视表的页面上显示照片时出现问题

时间:2019-06-20 12:19:19

标签: php sql pdo

出于学习目的,我正在oop php中针对属性/广告开发cms。我为每个媒体资源/广告和三张桌子都设有照片库。

properties (id, location, price, main_photo_id)

property_photo (id, property_id, photo_id)

photos (id, name, extension)

我正在尝试在页面上(来自main_photo_id)显示主照片,该页面与photo_id(来自property_photo)具有相同的ID,并且与photos表中的ID相同。我需要从照片表中选择名称和扩展名,然后通过查询连接到main_photo_id,但是当我编写查询时,页面上没有结果,当我使用vardump变量时,它说的是bool(false),但是在数据库中它正确地更改了main_photo_id。任何帮助表示赞赏。这是我的代码:

AdModel:

public function showMainPhoto($id)
{
    $this->db->query('SELECT p.id, p.name, p.extension FROM photos AS p
      RIGHT JOIN property_photo AS pp ON pp.photo_id = p.id 
      RIGHT  JOIN properties AS pro ON pro.main_photo_id = pp.photo_id
      WHERE pro.main_photo_id = :main_photo_id');
    $this->db->bind(':main_photo_id', $id);
    $row = $this->db->single();

    return $row;
}

AdsController:

public function viewAction()
 {
    if (!isset($_GET['id'])) {
        $ad_id = $_SESSION['ad_id'];
    } else {
        $ad_id = $_GET['id'];
    }

    $ad_data = $this->AdModel->adData1($ad_id);
    $data = $this->AdModel->getPhotoForPropertyView($ad_id);
    $data1 = $this->AdModel->showMainPhoto($ad_id);
    var_dump($data1);
    $data2 = $this->AdModel->getPhotosForProperty($ad_id);

    $this->view->render('ads/view', $data, $ad_data, $data1, $data2);
 }

view.php:

<picture>
    <h1>Main Photo</h1>
        <img src="<?php echo '/public/photos/'.$data1->name.'.'.$data1->extension ?>" class="img-fluid img-thumbnail" width="350" height="350">
</picture>

0 个答案:

没有答案