PDA

View Full Version : confusing myself with these if statments


AN-net
07-28-2005, 12:50 AM
ok if the user has set buddies and the user can not view the journal as of yet it will continue into this if statement but my question is:
what if the user has set buddies to view but $view is false will continue to the whocanview check or will it stop at buddies check because we have fulfilled the requirement?


if($entry['journal_private'])
{
if($bbuserinfo['userid'] != 0)
{
if(($bbuserinfo['userid'] == $entry['journalist_id']) OR ($bbuserinfo['usergroupid']==6))
{
$view_journal= true;
}
elseif($entry['journal_allowbuddies'] == 1 AND !$view)
{
if(isset($entry['jbuddylist']))
{
$buddies= explode(' ', $entry['jbuddylist']);
if(in_array($bbuserinfo['userid'], $buddies))
{
$view_journal= true;
}
else
{
$view_journal= false;
}
}
}
elseif(isset($entry['journal_whocanview']) AND !$view)
{
$wcv= explode(',', $entry['journal_whocanview']);
if(in_array($bbuserinfo['userid'], $wcv))
{
$view_journal= true;
$isbuddy= true;
}
}
else
{
$view_journal= false;
}
}
else
{
$view_journal= false;
}
}


also is there maybe another way i can check all of this stuff without these killer if statements?

Guest190829
07-28-2005, 02:42 AM
Well if you want it to continue, despite the previous elseif being true, then you'd replace the elseif with an if statement. If you don't leave it as elseif.

Paul M
07-28-2005, 03:16 AM
Try ;


if($entry['journal_private'])
{
$view_journal= false;
if($bbuserinfo['userid'])
{
if(($bbuserinfo['userid'] == $entry['journalist_id']) OR ($bbuserinfo['usergroupid']==6))
{
$view_journal= true;
}
elseif(!$view)
{
if($entry['journal_allowbuddies'] == 1 AND isset($entry['jbuddylist']))
{
$buddies= explode(' ', $entry['jbuddylist']);
if(in_array($bbuserinfo['userid'], $buddies))
{
$view_journal= true;
}
}
elseif(isset($entry['journal_whocanview']))
{
$wcv= explode(',', $entry['journal_whocanview']);
if(in_array($bbuserinfo['userid'], $wcv))
{
$view_journal= true;
$isbuddy= true;
}
}
}
}
}

It should do the same. Ignore the space at the start of line 1 - the forum seems to be adding that.

AFAIK;


if
{
//code here//
}
elseif
{
//other code here//
}is just a short version of


if
{
//code here//
}
else
{
if
{
//other code here//
}
}
It's usually easier to follow them if you remember this. :)

AN-net
07-28-2005, 01:27 PM
ok ty guys, ill talk this to myself today and straighten out so it flows correctly:D