我有一个 sql 查询,但我想确定如果有人没有上传头像(avatar_filename),它会显示一个替代头像(/images/avatars/default.jpg)。
我一直在看这个网站上的条件,并试图使用它们但没有成功。
这是我目前的工作查询:
$query = "SELECT exp_forum_topics.last_post_author_id, exp_forum_topics.title, exp_forum_topics.topic_id, exp_forum_topics.last_post_date, exp_members.member_id, exp_members.screen_name, exp_members.avatar_filename ".
"FROM exp_forum_topics, exp_members ".
"WHERE exp_forum_topics.last_post_author_id = exp_members.member_id ".
"ORDER BY exp_forum_topics.last_post_date DESC ".
"LIMIT 4";
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
echo '<img src="/images/avatars/';
echo $row['avatar_filename'];
echo '" />';
echo "<h3><a href='/forum/viewthread/";
echo $row['topic_id'];
echo "'>";
echo $row['title'];
echo "</a></h3>";
echo "<p>by <a href='/forum/members/";
echo $row['last_post_author_id'];
echo "'>";
echo $row['screen_name'];
echo "</a></p>";
}