Uutiset:

Bored?  Looking to kill some time?  Want to chat with other SMF users?  Join us in IRC chat or Discord

Main Menu
Advertisement:

using an IF staement inside an IF statement - how?

Aloittaja Gobo, joulukuu 27, 2006, 07:46:46 AP

« edellinen - seuraava »

Gobo

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

Dannii

You need to use brackets.If (something)
{
    code;
    if (something2)
    {
        code;
    }
    else
    {
        code;
    }
}
elseif (something)
{
    code;
}
else
{
    code;
}
"Never imagine yourself not to be otherwise than what it might appear to others that what you were or might have been was not otherwise than what you had been would have appeared to them to be otherwise."

Gobo

#2
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)

Gobo

nope dosent have any adverse side effects :D

Thanks for the help

Advertisement: