News:

Wondering if this will always be free?  See why free is better.

Main Menu

Turn this into a function?

Started by mephisto_kur, October 08, 2003, 10:24:23 PM

Previous topic - Next topic

mephisto_kur

Can someone help me turn this into a function?


  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>
She put her foot down on the oscillation pedal - she was a transdimensional speeder!



mephisto_kur

#1
BTW, this is what I have:


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");
}


Now it doesn't give me an error, but it doesn't do *anything* either.
She put her foot down on the oscillation pedal - she was a transdimensional speeder!



Haase

you need $db_prefix in your globals.

and I think you need $username too.
Find out about Enigma, the portal built exclusively for YaBB SE will be continuing it's work towards SMF

mephisto_kur

Yeah, figured that out.  Still doesn't work, tho.
She put her foot down on the oscillation pedal - she was a transdimensional speeder!



Haase

you're not actually outputting anything.  maybe try return $yyavatar; or echo $yyavatar; or something like that.
Find out about Enigma, the portal built exclusively for YaBB SE will be continuing it's work towards SMF

mephisto_kur

I don't think you understand.  I want to use a yabb tag.
She put her foot down on the oscillation pedal - she was a transdimensional speeder!



Aquilo

I put this in subs.php after function yylogo() but I dont think it matters where you put it and called it with <yabb avatar> and it showed the avatar *also note I did it with enigma09a!


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=\"\" />";
          }
   }
   echo ($username == 'Guest') ? "<img src=\"$facesurl/blank.gif\" border=\"0\" alt=\"\" />" : "$pic";
}



Aquilo

This also worked  :D

function yyavatar()
{
   global $userpic_width, $userpic_height, $facesurl, $username, $db_prefix;
   $grab_avatar = mysql_query("SELECT avatar FROM {$db_prefix}members WHERE memberName='$username'");
   $avatar[] = mysql_fetch_array($grab_avatar);

   echo '<img src="', ($username == 'Guest') ? $facesurl.'/blank.gif"' : (stristr($avatar[0][avatar],"http://") ?
   $avatar[0][avatar].'" '.$width.' '.$height : $facesurl.'/'.$avatar[0][avatar]), ' border="0" alt="User Avatar" />';
}

[Unknown]

YaBB SE captures output, so you have to echo it.

-[Unknown]

mephisto_kur

I've got it working as a standalone funtion, but does it *have to* be in Subs.php to be picked up as a tag?
She put her foot down on the oscillation pedal - she was a transdimensional speeder!



[Unknown]

Quote from: mephisto_kur on October 09, 2003, 10:16:39 AM
I've got it working as a standalone funtion, but does it *have to* be in Subs.php to be picked up as a tag?

No it can be anywhere... just as long as it's defined before the template_header() call.

-[Unknown]

mephisto_kur

Okay, let me explain exactly what is going on.  I understand what you mean, but I don't know *any* php so bear with me ;D

I have this in a file other than Subs.php:


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");
   return $yyavatar;
}


If I do an "echo yyavatar();" line anywhere it gives me what I want.

Now, to make it a yabb tag, I need to define the function before the template_header is called.  How would I do that?
She put her foot down on the oscillation pedal - she was a transdimensional speeder!



[Unknown]

Umm... I think the FUNCTION might have to echo it, not just return it.

Just means that where ever you put it... hsa to be looked at by PHP at some point.

-[Unknown]

mephisto_kur

Ahah.  That got it.  Funny thing is, I tried that before and while it did work when I used the tag, it also made it appear on every page in the upper left corner.

Thanks for the help!
She put her foot down on the oscillation pedal - she was a transdimensional speeder!



Advertisement: