繁体   English   中英

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

[英]How to display user accounts picture and name inside a box from database in html page using php and mysqli?

我想显示数据库中所有用户帐户的照片和名称,并将一个用户帐户的照片和名称放在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>

这是我上传的图片

您可以为任务添加一些线框吗?

这样,我认为您需要这样的东西:

<div>
    <a href="$linkToUserProfile"><img src="$imgSource" alt="" title=""></a>
    <a href="$linkToUserProfile">$userName</a>
</div>
#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'>";
        }
     }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM