Changing a condition based on gender...

Started by TechnoDragon, March 26, 2006, 07:20:32 PM

Previous topic - Next topic

TechnoDragon

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>';
Don't tell me to get into shape...I have a shape...It is round!


DemonicInfluence

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..

TechnoDragon

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?
Don't tell me to get into shape...I have a shape...It is round!


DemonicInfluence

#3
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..

TechnoDragon

would it help if i posted the entire block of code?
Don't tell me to get into shape...I have a shape...It is round!


DemonicInfluence

No, this is the only thing that really matters in it.. Anyway, did u test it?

TechnoDragon

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)
Don't tell me to get into shape...I have a shape...It is round!


DemonicInfluence

Does the first bit of code work? Or is it only the 2nd one that fails?

fwitt

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
}




Kindred

demonic...   rather than elseif, just use else...

if female

elseif male

else   (if anything else - is implied)

Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

fwitt

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
  }
}


DemonicInfluence

Ya, I was thinking around your lines fwitt.. Just heheh, not as good :)


TechnoDragon

It ignored the gender call altogether when it did work...otherwise it caused a parse error.
Don't tell me to get into shape...I have a shape...It is round!


DemonicInfluence

Ughh. CAn't you just say not context gender female with the "!"?

TechnoDragon

lol..i am getting the feeling that possibly this can't be done  :D
Don't tell me to get into shape...I have a shape...It is round!


DemonicInfluence

Of course it can! Just we need to work on it!

TechnoDragon

Quote from: DemonicInfluence on March 29, 2006, 01:09:28 PM
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.
Don't tell me to get into shape...I have a shape...It is round!


Advertisement: