Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: TechnoDragon - maaliskuu 26, 2006, 07:20:32 IP

Otsikko: Changing a condition based on gender...
Kirjoitti: TechnoDragon - maaliskuu 26, 2006, 07:20:32 IP
Could anyone help re-write this so that it will choose based on gender?  In other words, if the user is female, use a different wav and gif.  everyone else would use the one in the code.

                   if($context['user']['unread_messages']>0)
                        echo '<br />'.$bullet.'<a style="font-weight: bold; " href="', $scripturl, '?action=pm">' .$txt['tp-pm2'].' ',$context['user']['unread_messages'] , ' <img src="' . $settings['images_url'] . '/msg.gif" border="0"><bgsound src="' . $settings['images_url'] . '/Mail01.wav" border="0"></a>';
Otsikko: Re: Changing a condition based on gender...
Kirjoitti: DemonicInfluence - maaliskuu 27, 2006, 05:02:42 IP
if(($context['user']['unread_messages']>0) && ($context['member']['gender']['name'] == 'f')
                        echo '<br />'.$bullet.'<a style="font-weight: bold; " href="', $scripturl, '?action=pm">' .$txt['tp-pm2'].' ',$context['user']['unread_messages'] , ' <img src="' . $settings['images_url'] . '/msg.gif" border="0"><bgsound src="' . $settings['images_url'] . '/Mail01.wav" border="0"></a>';


Try that..
Otsikko: Re: Changing a condition based on gender...
Kirjoitti: TechnoDragon - maaliskuu 27, 2006, 05:51:40 IP
great...that works...but how do i now add a line so that if they are not female then a different message and image is displayed?
Otsikko: Re: Changing a condition based on gender...
Kirjoitti: DemonicInfluence - maaliskuu 27, 2006, 06:33:21 IP
Add after that:

elseif(($context['user']['unread_messages']>0) && ($context['member']['gender']['name'] == 'm'))
{
echo '<br />'.$bullet.'<a style="font-weight: bold; " href="', $scripturl, '?action=pm">' .$txt['tp-pm2'].' ',$context['user']['unread_messages'] , ' <img src="' . $settings['images_url'] . '/msg.gif" border="0"><bgsound src="' . $settings['images_url'] . '/Mail01.wav" border="0"></a>';
}
elseif(($context['user']['unread_messages']>0) && ($context['member']['gender']['name'] == ''))
{
echo '<br />'.$bullet.'<a style="font-weight: bold; " href="', $scripturl, '?action=pm">' .$txt['tp-pm2'].' ',$context['user']['unread_messages'] , ' <img src="' . $settings['images_url'] . '/msg.gif" border="0"><bgsound src="' . $settings['images_url'] . '/Mail01.wav" border="0"></a>';
}


It prolly won't work well, because not sure about last elseif. However, I can't think of an easy way to say if unread_message > 0 and member isn't female..
This might do that more easily.
elseif(($context['user']['unread_messages']>0) && (!$context['member']['gender']['name'] == 'f'))
{
echo '<br />'.$bullet.'<a style="font-weight: bold; " href="', $scripturl, '?action=pm">' .$txt['tp-pm2'].' ',$context['user']['unread_messages'] , ' <img src="' . $settings['images_url'] . '/msg.gif" border="0"><bgsound src="' . $settings['images_url'] . '/Mail01.wav" border="0"></a>';
}


Not sure. Maybe.. Haven't tested..

Try the 2nd one first, if it works, should be more efficient..
Otsikko: Re: Changing a condition based on gender...
Kirjoitti: TechnoDragon - maaliskuu 27, 2006, 07:17:57 IP
would it help if i posted the entire block of code?
Otsikko: Re: Changing a condition based on gender...
Kirjoitti: DemonicInfluence - maaliskuu 28, 2006, 06:15:35 AP
No, this is the only thing that really matters in it.. Anyway, did u test it?
Otsikko: Re: Changing a condition based on gender...
Kirjoitti: TechnoDragon - maaliskuu 28, 2006, 08:16:09 AP
sorry, yes i did last night....tried several different ways and either it works like it always did or it causes a parse error (it doesn't tell me what was causing the error, just that the line that holds the img and wav tags is the error)
Otsikko: Re: Changing a condition based on gender...
Kirjoitti: DemonicInfluence - maaliskuu 28, 2006, 01:01:11 IP
Does the first bit of code work? Or is it only the 2nd one that fails?
Otsikko: Re: Changing a condition based on gender...
Kirjoitti: fwitt - maaliskuu 28, 2006, 01:20:06 IP
surely



if(($context['user']['unread_messages']>0) && ($context['member']['gender']['name'] == 'f')) {
echo for female
}
elseif(($context['user']['unread_messages']>0) && ($context['member']['gender']['name'] == 'f'))
echo for other case
}



Otsikko: Re: Changing a condition based on gender...
Kirjoitti: Kindred - maaliskuu 28, 2006, 01:49:57 IP
demonic...   rather than elseif, just use else...

if female

elseif male

else   (if anything else - is implied)

Otsikko: Re: Changing a condition based on gender...
Kirjoitti: fwitt - maaliskuu 28, 2006, 02:49:51 IP
dont we still want the ($context['user']['unread_messages']>0)

so



if(($context['user']['unread_messages']>0) && ($context['member']['gender']['name'] == 'f')) {
echo for female
}
elseif($context['user']['unread_messages']>0) {
echo for other case
}



as the original code we are editing was only passed if there are unread messages
either that or nest anouther if statement for the gender query



if($context['user']['unread_messages']>0) {
  if($context['member']['gender']['name'] == 'f') {
  echo for female
  }
  else {
  echo for other case
  }
}

Otsikko: Re: Changing a condition based on gender...
Kirjoitti: DemonicInfluence - maaliskuu 28, 2006, 03:01:17 IP
Ya, I was thinking around your lines fwitt.. Just heheh, not as good :)

Otsikko: Re: Changing a condition based on gender...
Kirjoitti: TechnoDragon - maaliskuu 28, 2006, 09:03:25 IP
It ignored the gender call altogether when it did work...otherwise it caused a parse error.
Otsikko: Re: Changing a condition based on gender...
Kirjoitti: DemonicInfluence - maaliskuu 29, 2006, 07:09:48 AP
Ughh. CAn't you just say not context gender female with the "!"?
Otsikko: Re: Changing a condition based on gender...
Kirjoitti: TechnoDragon - maaliskuu 29, 2006, 08:13:17 AP
lol..i am getting the feeling that possibly this can't be done  :D
Otsikko: Re: Changing a condition based on gender...
Kirjoitti: DemonicInfluence - maaliskuu 29, 2006, 01:09:28 IP
Of course it can! Just we need to work on it!
Otsikko: Re: Changing a condition based on gender...
Kirjoitti: TechnoDragon - maaliskuu 29, 2006, 10:19:39 IP
Lainaus käyttäjältä: DemonicInfluence - maaliskuu 29, 2006, 01:09:28 IP
Of course it can! Just we need to work on it!

ALRIGHT!

LOL...If it helps, what I am trying to do is have it check first if the member has any new PM's, then chaeck to see what sex (if defined) they are and then show the flashing image and sound based on the sex (or lack thereof).

So...If they are female it would should a little pink flashing msg icon and play, say, Garth Brooks saying you have mail...if they are male (or no sex defined) then it would show a flashing blue icon, and play some sexy woman saying you have mail.