我一直在尝试将图像显示到 heredoc 中,但它无法工作,而且我没有收到任何错误 但是,如果我将它们显示出来,如果 heredoc 它们显示得很好。可能是什么问题? 对于任何帮助,我将不胜感激。 这是代码,我确实在 heredoc 和 out 中显示了两次图像,以便您获得清晰的 View 。
<?Php
$target = "image_uploads/";
$image_name = (isset($_POST['image_name']));
$query ="select * from
tish_user inner join tish_images
on tish_user.user_id = tish_images.user_id
WHERE tish_images.prof_image = 1";
$result= $con->prepare($query);
$result->execute();
$table = <<<ENDHTML
<div style ="text-align:center;">
<h2>Client Review Software</h2>
<table id ="heredoc" border ="0" cellpaddinig="2" cellspacing="2" style = "width:100%" ;
margin-left:auto; margin-right: auto;>
<tr>
<th>Name</th>
<th>Last Name</th>
<th>Ref No</th>
<th>Cell</th>
<th>Picture</th>
</tr>
ENDHTML;
while($row = $result->fetch(PDO::FETCH_ASSOC)){
$date_created = $row['date_created'];
$user_id = $row['user_id'];
$username = $row['username'];
$image_id = $row['image_id'];
#this is the Tannery operator to replace a pic when an id do not have one
$photo = ($row['image_name']== null)? "me.png":$row['image_name'];
#display image
# I removed this line up to here
echo '<img src="'.$target.$photo.'" width="100" height="100">';
$table .= <<<ENDINFO
<tr>
<td><a href ="client_details.php?user_id=$user_id">$username </a></td>
<td>$image_id</td>
<td></td>
<td>c</td>
<td><img src="'.$target.$photo.'" width="100" height="100">
</td>
</tr>
ENDINFO;
}
$table .= <<<ENDHTML
</table>
<p>$numrows"Clients</p>
</div>
ENDHTML;
echo $table;
?>
最佳答案
使用heredoc
并在未显示图像的浏览器中检查其来源
图片源应该是这样的<img src="'.../images/.me.png.'" ...
这是错误的,因为您可以看到单引号和额外的。 (句号)在 img src 的双引号内
试试这段代码
$table .= <<<ENDINFO
<tr>
<td><a href ="client_details.php?user_id=$user_id">$username </a></td>
<td>$image_id</td>
<td></td>
<td>c</td>
<td><img src="{$target}{$photo}" width="100" height="100">
</td>
</tr>
ENDINFO;
}
所以
<img src="'.$target.$photo.'" width="100" height="100">
会是
<img src="{$target}{$photo}" width="100" height="100">
如果解决了请告诉我,请始终检查浏览器的 HTML 源 view source
查看打印内容的选项
关于php - 如何将数据库中的图片显示到heredoc中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15020370/