gpt4 book ai didi

php - 在搜索时显示用户头像或默认头像

转载 作者:行者123 更新时间:2023-11-29 09:13:39 24 4
gpt4 key购买 nike

我的 PHP 搜索脚本有问题。我正在建立一个社交网站,人们可以在其中搜索用户、事件或俱乐部。我希望搜索结果显示用户头像拇指或默认拇指(如果没有上传)。我在本地主机上进行测试。用户头像存储在 User_Images (c:\wamp\www\NNL\User_Images) 文件夹中,而默认头像存储在 c:\wamp\www\NNL\Style\Images\中default_avatar.png。

以下是我的 PHP 代码:

<?php
while ($row_user = mysql_fetch_assoc($user))
{
echo "\n<table width='500' border='0'>";
echo "\n\t<tr>";
echo "<td width='50' height='50' align='center' valign='middle'><a href='user_view.php?user_id=".$row_user['user_id']."'>
<img src=User_Images/$row_user[picture_thumb_url] !=''? $row_user[picture_thumb_url]: '../Style/Images/default_avatar.png'
border='0' height='50' width='50'/></a></td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_user['user_first_name']. "</td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_user['user_last_name']. "</td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_user['username']. "</td>";
echo "<td width='30'><a class='text_12_link_green' href='user_view.php?user_id=".$row_user['user_id']."'>View</a></td>";
echo "\n\t</tr>";
echo "\n</table>";
}
?>
<?php
while ($row_event = mysql_fetch_assoc($event))
{
echo "\n<table width='500' border='0'>";
echo "\n\t<tr>";
echo "<td width='50' height='50' align='center' valign='middle'><a href='#table_index.php'>
<img src='Images/$row_event[event_thumb_url]' border='0' height='50' width='50'/></a></td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_event['event_name']. "</td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_event['event_venue']. "</td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_event['event_date']. "</td>";
echo "<td width='30'><a class='text_12_link_green' href='#user_view.php?user_id=".$row_user['username']."'>View</a></td>";
echo "\n\t</tr>";
echo "\n</table>";
}
?>
<?php
while ($row_establishment = mysql_fetch_assoc($establishment))
{
echo "\n<table width='500' border='0'>";
echo "\n\t<tr>";
echo "<td width='50' height='50' align='center' valign='middle'><a href='#table_index.php'>
<img src='Establishment_Images/$row_establishment[establishment_thumb_url]' border='0' height='50' width='50'/></a></td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_establishment['establishment_name']. "</td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_establishment['location_name']. "</td>";
echo "<td width='140' class='ordinary_text_12'>" .$row_establishment['establishment_pricing']. "</td>";
echo "<td width='30'><a class='text_12_link_green' href='#user_view.php?user_id=".$row_user['username']."'>View</a></td>";
echo "\n\t</tr>";
echo "\n</table>";
}
?>

问题出在 $row_user while 循环中,我试图回显 $row_user 拇指。现在,如果用户有头像,它会显示图像,但如果用户没有头像,它根本不返回图像。我哪里出错了?

最佳答案

你可以这样做,尽管它不完全可读。

echo "<td width='50' height='50' align='center' valign='middle'><a href='user_view.php?user_id=".$row_user['user_id']."'>
<img src=User_Images/" . ( $row_user['picture_thumb_url'] != '' ? $row_user['picture_thumb_url'] : '../Style/Images/default_avatar.png' ) . " border='0' height='50' width='50'/></a></td>";

您最好事先执行条件,然后回显变量:

更新:

$thumbnail = $row_user['picture_thumb_url'] != '' ? $row_user['picture_thumb_url'] : '../Style/Images/default_avatar.png';

echo "<td width='50' height='50' align='center' valign='middle'><a href='user_view.php?user_id=".$row_user['user_id']."'>
<img src=User_Images/$thumbnail border='0' height='50' width='50'/></a></td>";

关于php - 在搜索时显示用户头像或默认头像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4794569/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com