坐在这里并按照教程,但有一些我想改变的东西。 我在我的用户的前端网站上拍了照片,当我将鼠标悬停在他们的照片上时,我可以看到他们的用户名。
希望将用户名置于其图片下方。 任何人都知道如何做到这一点。?
<?php
include_once("php_includes/check_login_status.php");
$sql = "SELECT username, avatar FROM users WHERE avatar IS NOT NULL AND activated='1' ORDER BY RAND() LIMIT 32";
$query = mysqli_query($db_conx, $sql);
$userlist ="";
while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
$u = $row["username"];
$avatar = $row["avatar"];
$profile_pic = 'user/'.$u.'/'.$avatar;
$userlist .= '<a href="user.php?u='.$u.'" title="'.$u.'"><img src="'.$profile_pic.'" alt="'.$u.'" style="width:100px; height:100px; margin:10px;"></a>';
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta charset="UTF-8">
<head>
<link rel="stylesheet" href="style/style.css">
</head>
<body>
<?php include_once("template_pageTop.php"); ?>
<div id="pageMiddle">
<?php echo $userlist; ?>
</div>
<?php include_once("template_pageBottom.php"); ?>
</body>
</html>
答案 0 :(得分:2)
您可以使用以下代码。只需对while循环进行一些调整
while ($row = mysqli_fetch_array($query, MYSQLI_ASSOC)) {
$u = $row["username"];
$avatar = $row["avatar"];
$profile_pic = 'user/'.$u.'/'.$avatar;
$userlist .= '<a href="user.php?u='.$u.'" title="'.$u.'"><img
src="'.$profile_pic.'" alt="'.$u.'" style="width:100px; height:100px;
margin:10px;"></a><br><h3>'.$u.'</h3>';
}