Simple Machines Community Forum

General Community => Scripting Help => Aiheen aloitti: Gobo - joulukuu 27, 2006, 07:46:46 AP

Otsikko: using an IF staement inside an IF statement - how?
Kirjoitti: Gobo - joulukuu 27, 2006, 07:46:46 AP
hi

how do i declare an IF statement inside an IF statement?

the one I am looking at now is:


if($context['TPortal']['dlaction']=='item')
echo '
<a href="'.$dlitem['href'].'"><img src="' . $settings['images_url']. '/TPdownloadfile.gif" border="0" align="right" alt="" /></a>';


I want it to be something like:


    global $user_info;
if ($user_info['is_guest'])
echo
if($context['TPortal']['dlaction']=='item')
echo '
<a href="....link here......"><img src="' . $settings['images_url']. '/TPdownloadfile.gif" border="0" align="right" alt="" /></a>';
else
echo
if($context['TPortal']['dlaction']=='item')
echo '
<a href="'.$dlitem['href'].'"><img src="' . $settings['images_url']. '/TPdownloadfile.gif" border="0" align="right" alt="" /></a>';


so basically it will check if the user is a guest then it will give them another link otherwise give them the original link
thanks
aku
Otsikko: Re: using an IF staement inside an IF statement - how?
Kirjoitti: Dannii - joulukuu 27, 2006, 07:52:37 AP
You need to use brackets.If (something)
{
    code;
    if (something2)
    {
        code;
    }
    else
    {
        code;
    }
}
elseif (something)
{
    code;
}
else
{
    code;
}
Otsikko: Re: using an IF staement inside an IF statement - how?
Kirjoitti: Gobo - joulukuu 27, 2006, 07:53:14 AP
Thanks figured it out :D


    global $user_info;
if (($user_info['is_guest'])&&($context['TPortal']['dlaction']=='item'))
echo '
<a href="....link here......"><img src="' . $settings['images_url']. '/TPdownloadfile.gif" border="0" align="right" alt="" /></a>';
else
echo '
<a href="'.$dlitem['href'].'"><img src="' . $settings['images_url']. '/TPdownloadfile.gif" border="0" align="right" alt="" /></a>';



now we have Guests can only view in TP
and members can download
woo hoo :D

PS: do u think the 2 statements are basically the same or will there be differences ? (in ur professional opinion as a php coder)
Otsikko: Re: using an IF staement inside an IF statement - how?
Kirjoitti: Gobo - joulukuu 27, 2006, 10:04:02 AP
nope dosent have any adverse side effects :D

Thanks for the help