我尝试显示图片,但从不显示
<?php
$st=$con->prepare("select * from test");
$st->execute();
$rs=$st->get_result();
while($row=$rs->fetch_assoc())
{
echo '<div class="blog-comments__item d-flex p-3">
<div class="blog-comments__avatar mr-3">
<img src="http://graph.facebook.com/" '. $row["user_id"] .' "/picture?type=large" alt="User avatar" />
</div>
<div class="blog-comments__content">
<div class="blog-comments__meta text-muted">
<a class="text-secondary" href="#"></a>
</div>
<p class="m-0 my-1 mb-2 text-muted"></p>
</div>
</div>';
}
?>
获取用户头像而不是真实图片
答案 0 :(得分:0)
您有几次错别字。删除img
标签的src
:/" '. $row["user_id"] .' "/
这部分的引号和空格。您当前的代码将产生一个URI,如
http://graph.facebook.com/" 12345 "/picture?type=large
您的意思是:/' . $row["user_id"] . '/
,如:
echo '<div class="blog-comments__item d-flex p-3">
<div class="blog-comments__avatar mr-3">
<img src="http://graph.facebook.com/' . $row["user_id"] . '/picture?type=large" alt="User avatar" /> </div>
<div class="blog-comments__content">
<div class="blog-comments__meta text-muted">
<a class="text-secondary" href="#"></a>
</div>
<p class="m-0 my-1 mb-2 text-muted"></p>
</div>
</div>';
请注意,这是假设您的数据库代码正确并且您正在正确保存和检索ID。