Displaying avatar with mysql query, need help

Started by Ride, November 09, 2005, 08:50:55 PM

Previous topic - Next topic

Ride

What do I need to add to this code so it will show a default avatar if the user doesn't have one?

$result = mysql_query("select m.ID_MEMBER, m.avatar, m.realName, m.gender, m.location, t.value, a.ID_ATTACH from (smf_members m left join smf_themes t on m.ID_MEMBER = t.ID_MEMBER) left join smf_attachments a on t.ID_MEMBER = a.ID_MEMBER WHERE t.variable = 'coords' AND t.value != '' ");

while($row = mysql_fetch_array( $result )) {

// An attached/uploaded avatar?
if (!empty($row['ID_ATTACH']))
$row['avatar'] = $scripturl . '?action=dlattach;id=' . $row['ID_ATTACH'] . ';type=avatar';
elseif (strtolower(substr($row['avatar'], 0, 7)) != 'http://')
$row['avatar'] = '/forum/avatars/' . $row['avatar'];

echo '
<a href="/forum/index.php?action=profile;u=', $row['ID_MEMBER'], '"><img src="', $row['avatar'] ,'" border="1" alt="', $row['realName'], '" /></a><br />
<span style="font-size: smaller;">', $row['realName'], '</span><br />' .$row['value']. '<br> ' .$row['location']. '<br /><br />';


emmaderijk



emmaderijk

Quote from: Ride on November 09, 2005, 08:50:55 PM
What do I need to add to this code so it will show a default avatar if the user doesn't have one?

$result = mysql_query("select m.ID_MEMBER, m.avatar, m.realName, m.gender, m.location, t.value, a.ID_ATTACH from (smf_members m left join smf_themes t on m.ID_MEMBER = t.ID_MEMBER) left join smf_attachments a on t.ID_MEMBER = a.ID_MEMBER WHERE t.variable = 'coords' AND t.value != '' ");

while($row = mysql_fetch_array( $result )) {

// An attached/uploaded avatar?
if (!empty($row['ID_ATTACH']))
$row['avatar'] = $scripturl . '?action=dlattach;id=' . $row['ID_ATTACH'] . ';type=avatar';
elseif (strtolower(substr($row['avatar'], 0, 7)) != 'http://')
$row['avatar'] = '/forum/avatars/' . $row['avatar'];

echo '
<a href="/forum/index.php?action=profile;u=', $row['ID_MEMBER'], '"><img src="', $row['avatar'] ,'" border="1" alt="', $row['realName'], '" /></a><br />
<span style="font-size: smaller;">', $row['realName'], '</span><br />' .$row['value']. '<br> ' .$row['location']. '<br /><br />';


just  from a static address?

emma

Ride

Static Address?  Not sure what you mean.  Basically, the way it is now it shows the infamous red X if the user doesn't have a avatar set.  Just not sure what to do to have it display for example "noavatar.gif" instead of showing nothing.

emmaderijk

hi,

thanks, I will start playing the coming days and will inform you on the progress I make.

btw. You can also store a default avatar for your board for users that do not pick a avatar.. but I asume that you want the script to check if the avatar field is empty.



emma

Advertisement: