显示存储在数据库中 url 的照片

Displaying photos from url stored in database

这是我的数据库:

我正在尝试显示这样的图像

  <?php
$displaymyavatar="SELECT * FROM avatars INNER JOIN users ON avatars.users_id=users.id WHERE username='$login_session'";
 $result_set=mysqli_query($db,$displaymyavatar);
 while($row=mysqli_fetch_array($result_set)){?>
              <img class="avatar" src='<?=$_SERVER['HTTP_REFERER'] . $row['image_file'];?>' alt="">
 <?php };?>

我以为我找到了解决方案 here,但图像没有显示。图片上传到文件夹"uploads"

亲戚 link 会为您工作吗?如果是这样,您应该可以使用以下代码片段。

<?php
   $displaymyavatar="SELECT * FROM avatars INNER JOIN users ON avatars.users_id=users.id WHERE username='$login_session'";
   $result_set=mysqli_query($db,$displaymyavatar);
   while($row=mysqli_fetch_array($result_set)){ ?>
       <img class="avatar" src="./<?php echo $row['image_file']; ?>" alt="">
<?php };?>

你可以使用foreach循环

<?php foreach ($result_set as $key => $r): ?>
    <img src="<?php echo $r['image_file'] ?>" />
<?php endforeach ?>

这个有效:

     <?php
$displaymyavatar="SELECT * FROM avatars INNER JOIN users ON avatars.users_id=users.id WHERE username='marydoe'";
 $result_set=mysqli_query($db,$displaymyavatar);
 while($row=mysqli_fetch_array($result_set)){?>
              <img class="avatar" src="core/<?php echo $row['image_file'] ?>" />
 <?php };?>