如何使用php和mysqli在html页面的数据库中显示用户帐户图片和名称?

问题描述 投票:0回答:2

我想显示数据库中的所有用户帐户照片和名称,并将一个用户照片和名称放在div标签中,同样地将所有帐户放入一个重定向到所点击帐户的链接。但是我在如何显示它时遇到了问题。如果仍然不清楚,请尝试在线购物网站进行描绘,其中每个名称的产品都单独放在自己的包装盒中。请帮忙,我实际上是想为我的教育项目建立一个社交网站。谢谢。继承我的代码:

$sql = "SELECT * FROM user WHERE NOT username = '$username'";
$account = array();
$photo1 = array();
$result = $conn->query($sql);
if($result->num_rows > 0)
{
    while($row = $result->fetch_assoc())
    {
        $account[] = $row['username'];
        $a = $row['photo'];
        $photo1[] = "<img src = '$a' alt = 'profile photo' width = '100px' height = '100px'>";
    }
}

and Heres a section of my html code: 
<div>
    <?php echo implode(', ',$photo1); ?>    
    <?php echo implode(', ',$account);?>
</div>

This is the image that I uploaded

php html mysqli phpmyadmin
2个回答
0
投票

你能为你的任务添加一些线框吗?

通过这种方式,我认为你需要这样的东西:

<div>
    <a href="$linkToUserProfile"><img src="$imgSource" alt="" title=""></a>
    <a href="$linkToUserProfile">$userName</a>
</div>

0
投票
#try this and then add html as you need
   $sql = "SELECT * FROM user  ";
   $result = $conn->query($sql);
   if($result->num_rows > 0)
    {
      while($row = $result->fetch_assoc())
        {
          echo $row['username'];
          $a = 'www.yourdomain.com/usriamegefolder/'.$row['photo'];
          echo "<img src = '$a' alt = 'profile photo' width = '100px' height = '100px'>";
        }
     }
© www.soinside.com 2019 - 2024. All rights reserved.