我不明白为什么我的photos
没有显示。 photos
div在放置在echo语句之外时显示正常,但在echo时它不会呈现。我的div有以下结构:
userposts_panel
photos_div
photos
以下是所有div存在的代码(完整):
<div class="userposts_panel">
<div class="photos_div">
<table>
<tr>
<?php
// get pictures from DB
$get_user_pics = mysqli_query ($connect, "SELECT * FROM user_photos WHERE uploaded_by='$username'"); // maybe $user
$check_rows = mysqli_num_rows ($get_user_pics);
while ($row = mysqli_fetch_assoc($get_user_pics)){
$user_id = $row ['id'];
$photo_url = $row ['img_url'];
$phot_desc = $row ['photo_desc'];
$photo_uploaded_by = $row ['uploaded_by'];
$photo_uloaded_on= $row ['uploaded_on'];
$uid = $row ['uid'];
echo "<td>
<div class='photos'>
<img src='$photo_url' height='170px' width='170px'/>
</div>
</td>";
}
?>
</tr>
</table>
</div>
</div>
</div>
.userposts_panel CSS:
.userposts_panel{
margin:0 auto;
height: auto;
text-align:left;
position:absolute;
top: 395px;
left:10px;
width: 800px;
background-color:#ffffff;
border-bottom: 1px solid #E1E3E4;
border-left: 1px solid #E1E3E4;
border-right: 1px solid #E1E3E4;
z-index:999;
}
.photos_div CSS:
.photos_div{
background-color: #FFFFFF;
width: 800px;
height: 500px;
}
.photos CSS:
.photos{
position:absolute;
top:0;
left:0;
margin-top:11px;
margin-left:5px;
background-color: #ffffff;
border: 1px solid red;
padding: 3px;
width: 200px;
height:200px;
margin-right: 5px;
text-align:center;
}
我只是不明白为什么div在回显时没有出现但在echo语句之外渲染得很好?任何帮助将不胜感激。
答案 0 :(得分:0)
尝试在echo语句中连接变量$ photo_url
<div class="userposts_panel">
<div class="photos_div">
<table>
<tr>
<?php
// get pictures from DB
$get_user_pics = mysqli_query ($connect, "SELECT * FROM user_photos WHERE uploaded_by='$username'"); // maybe $user
$check_rows = mysqli_num_rows ($get_user_pics);
while ($row = mysqli_fetch_assoc($get_user_pics)){
$user_id = $row ['id'];
$photo_url = $row ['img_url'];
$phot_desc = $row ['photo_desc'];
$photo_uploaded_by = $row ['uploaded_by'];
$photo_uloaded_on= $row ['uploaded_on'];
$uid = $row ['uid'];
?>
<td>
<div class='photos'>
<img src='<?php echo $photo_url; ?>' height='170px' width='170px'/>
</div>
</td>
<?php
}
?>
</tr>
</table>
</div>
</div>