General Community > Scripting Help

Turn this into a function?

(1/3) > >>

mephisto_kur:
Can someone help me turn this into a function?


--- Code: ---  global $userpic_width, $userpic_height, $facesurl;

  //BEGIN Avatar Tag Code <yabb avatar>
  $grab_avatar = mysql_query("SELECT avatar FROM {$db_prefix}members WHERE  memberName='$username'");
  while ($avatar = mysql_fetch_array($grab_avatar)) {
  if (stristr($avatar[0],"http://") ) {
  $pic = "<img src=\"$avatar[0]\" $width $height border=\"0\" alt=\"\" />";
  }
  else {
  $pic = "<img src=\"$facesurl/$avatar[0]\" border=\"0\" alt=\"\" />";
  }
  }
  $yyavatar = ($username == 'Guest' ? "<img src=\"$facesurl/blank.gif\" border=\"0\" alt=\"\" />" : "$pic");
  //END Avatar Tag Code <yabb avatar>

--- End code ---

mephisto_kur:
BTW, this is what I have:


--- Code: ---function yyavatar()
{
   global $userpic_width, $userpic_height, $facesurl, $username, $db_prefix;
   $grab_avatar = mysql_query("SELECT avatar FROM {$db_prefix}members WHERE memberName='$username'");
   while ($avatar = mysql_fetch_array($grab_avatar))
   {
          if (stristr($avatar[0],"http://") )
          {
               $pic = "<img src=\"$avatar[0]\" $width $height border=\"0\" alt=\"\" />";
          }
          else
          {
               $pic = "<img src=\"$facesurl/$avatar[0]\" border=\"0\" alt=\"\" />";
          }
   }
   $yyavatar = ($username == 'Guest' ? "<img src=\"$facesurl/blank.gif\" border=\"0\" alt=\"\" />" : "$pic");
}

--- End code ---

Now it doesn't give me an error, but it doesn't do *anything* either.

Haase:
you need $db_prefix in your globals.

and I think you need $username too.

mephisto_kur:
Yeah, figured that out.  Still doesn't work, tho.

Haase:
you're not actually outputting anything.  maybe try return $yyavatar; or echo $yyavatar; or something like that.

Navigation

[0] Message Index

[#] Next page

Go to full version