在php数据库检索中打破img url

时间:2016-08-28 21:44:52

标签: php jquery html postgresql

这对我来说是一个非常棘手的问题。我正在查看我的PostgreSQL表,我的PHP查询和我的HTML,常识告诉我这应该100%工作。设计目标是迭代地显示与给定记录相关联的所有照片缩略图,并在模态中显示每个图像的更大版本。缩略图有效,但模态img URL只是一个目录(根据Chrome DevTools)。什么地方出了错?请随意提出澄清问题,我打算今天解决这个问题。

// Database Query Code
$dbconn = pg_connect("host=localhost dbname=biopro user=biopro password=") or die('Could not connect: ' . pg_last_error());
$record = $_POST['record'];
$search_db_photos = "SELECT res_key, res_filename FROM resources WHERE key_creator={$record} AND NOT res_type='pp' ORDER BY date_created DESC;";
$dbphotos = pg_query($search_db_photos);

......用循环构建的实际画廊。同样,缩略图工作,模态不要(意味着它们按预期弹出,但显示损坏的图像链接)。

   if (pg_num_rows($dbphotos) !=0 ) {
           echo '    <div class="cover-container">';
        for ($i = 0; $i < pg_num_rows($dbphotos); $i++) {
        $resource=pg_fetch_row($dbphotos);
        echo<<<HERE
<div class="cover-item" style="background-image: url('uploads/{$resource[1]}')" onclick="Modal('pic{$i}')"></div>";
HERE;
    } // END for() 1 of 2
    echo '</div>';

    for ($i = 0; $i < pg_num_rows($dbphotos); $i++) {
        $resource=pg_fetch_row($dbphotos);

        echo<<<HERE
<div class="modal fade" tabindex="-1" id="modalpic{$i}">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<img src="uploads/{$resource[1]}" alt="Img {$i}" class="uploadimg" style="max-width:100%; max-height:100%;">
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-warning pull-left" onclick="modResource('delete', '{$resource[0]}', '{$record}')">Delete</button>
<button type="button" class="btn btn-primary" onclick="modResource('upgrade', '{$resource[0]}', '{$record}')">Set as Primary</button>
</div>
</div>
</div>
</div>
HERE;
        } // END for()
    } // END if()
pg_close($dbconn);
} //END addPhotos()
addPhotos();

print_r($resource)

的输出
Array ( 
    [0] => 13
    [1] => wildlife2.jpg
)

psql的终端输出

=> SELECT res_filename FROM resources;
 res_filename  
---------------
 wildlife1.jpg
 wildlife1.jpg
 house.jpeg
 wildlife2.jpg
 house.jpeg
 ...

0 个答案:

没有答案