【发布时间】:2020-02-15 16:44:11
【问题描述】:
现在我的代码正在数据库中回显所有用户及其个人资料图片。我的目标是只回显会话用户名和个人资料图片。任何帮助,将不胜感激。谢谢。
<?php
$q = mysqli_query($db, "SELECT * FROM users");
while($row = mysqli_fetch_assoc($q)) {
echo $username['username'];
if($row['image'] == ""){
echo "<img width='100 height='100' src='/student/globalit/2019/GamerMedia/pages/images/ao.jpg' alt ='Default Profile Pic'>";
}
else{
echo "<img width='100' height='100' src='/student/globalit/2019/GamerMedia/pages/images/".$row['image']."' alt='Profile Pic'>";
}
echo "<br>";
}
?>
【问题讨论】:
-
听起来你只想显示当前用户,所以在你的
SELECT * FROM users中添加一个WHERE子句。 -
$username你在哪里定义的? -
试试:
"SELECT * FROM users WHERE username = '".$username['username']."'" -
用户名定义为
$username = $_SESSION['username'];,您添加的代码给了我这个错误:警告:/home/benrud/public_html/student/globalit/2019/GamerMedia/ 中的非法字符串偏移“用户名” pages/account.php 第 34 行