問題描述
我將如何從我的數據庫中顯示用戶個人資料圖片? (How would I go about displaying user profile pictures from my database?)
圖片已經在我的數據庫中,我正在嘗試在它們登錄後在窗口右上角的下拉菜單中顯示它們。這是我的網站目前正在做的事情:
右上角突出顯示的藍色部分應該是圖片已顯示,但顯然沒有顯示。但正如您在頁面下方看到的那樣,我的圖片顯示。我不確定為什麼它不會出現在下拉菜單中。我的下拉菜單的代碼在這裡:
<?php
include ('core.php');
include ('link.php');
include ('profile.php');
if(isset($_SESSION["steamid"]))
{
echo'<li class="dropdown">
<a href="" class="dropdown‑toggle profile waves‑effect" data‑toggle="dropdown" aria‑expanded=""><img src="'.$steamprofile['avatarfull'].'" alt="user‑img" class="img‑circle"> </a>
<ul class="dropdown‑menu">
<li class="notifi‑title">'.$steamprofile['personaname'].'</li>
<li><a href="profile.php"><i class="ti‑user m‑r‑5"></i> Profile</a></li>
<li><a href="usersettings.php"><i class="ti‑settings m‑r‑5"></i> Settings</a></li>
<li><a href="userhistory.php"><i class="ti‑book m‑r‑5"></i> History</a></li>
<li><a href="steamauth/logout.php"><i class="ti‑power‑off m‑r‑5"></i> Logout</a></li>
</ul>
</li>';
參考解法
方法 1:
you have to put the name of the folder that has the profiles pictures on
<img src='folder/'.$steamprofile['avatarfull'].'' alt="user‑img" class="img‑circle">
方法 2:
Select the url of the photo from the database table
Set a PHP Variable to that url ex.
$profileUrl = "URL";
Find the DIV that is your profile image and set the background of the div inside of you HTML/PHP file
</ol>
BELOW IS STEP 3
<style>
.profile {background‑image:url("<?php echo $profileUrl; ?>");}
</style>
<div class=".profile"></div>
方法 3:
You cannot have an echo
in an echo
:
echo'<li class="dropdown">
<a href="" class="dropdown‑toggle profile waves‑effect" data‑toggle="dropdown" aria‑expanded=""><img src="'.$steamprofile['avatarfull'].'" alt="user‑img" class="img‑circle"> </a>
<ul class="dropdown‑menu">
<li class="notifi‑title">'. echo $steamprofile['personaname'].'</li>
<li><a href="profile.php"><i class="ti‑user m‑r‑5"></i> Profile</a></li>
<li><a href="usersettings.php"><i class="ti‑settings m‑r‑5"></i> Settings</a></li>
<li><a href="userhistory.php"><i class="ti‑book m‑r‑5"></i> History</a></li>
<li><a href="steamauth/logout.php"><i class="ti‑power‑off m‑r‑5"></i> Logout</a></li>
</ul>
</li>';
Thus, you need to remove the echo
in echo $steamprofile['personaname']
.
Your code should be:
echo'<li class="dropdown">
<a href="" class="dropdown‑toggle profile waves‑effect" data‑toggle="dropdown" aria‑expanded=""><img src="'.$steamprofile['avatarfull'].'" alt="user‑img" class="img‑circle"> </a>
<ul class="dropdown‑menu">
<li class="notifi‑title">'. $steamprofile['personaname'].'</li>
<li><a href="profile.php"><i class="ti‑user m‑r‑5"></i> Profile</a></li>
<li><a href="usersettings.php"><i class="ti‑settings m‑r‑5"></i> Settings</a></li>
<li><a href="userhistory.php"><i class="ti‑book m‑r‑5"></i> History</a></li>
<li><a href="steamauth/logout.php"><i class="ti‑power‑off m‑r‑5"></i> Logout</a></li>
</ul>
</li>';
(by user6150781、Decapitatef、joeldesante、Panda)