PDA

View Full Version : Another vBull question...


Chicken
04-19-03, 08:36 PM
This specifically pertains to vBulletin, but hopefully it is general enough that that isn't improtant...

If I wanted to replace this:
$cantpostforumid=Z;

if ($cantpostforumid==$forumid AND ($bbuserinfo[usergroupid]!=6 OR $bbuserinfo[usergroupid]!=5 OR $bbuserinfo[usergroupid]!=7))
{

And instead of setting the $cantpostforumid=Z; variable and then using it a line later, wanted to change this to different values, how would I go about it?

Is there a way to set the variable in the first place, like...

$cantpostforumid=($forumid == 19 OR $forumid == 21 OR $forumid == 23 OR $forumid == 24 OR $forumid == 27);

-or could we just get rid of it and have ths infomation in the lines that follow like this:

if (($forumid == 19) OR ($forumid == 21) OR ($forumid == 23) OR ($forumid == 24) OR ($forumid == 27) AND ($bbuserinfo[usergroupid]!=6 OR $bbuserinfo[usergroupid]!=5 OR $bbuserinfo[usergroupid]!=7))
{

-or would the code be more like this (note change in grouping, deletion of parentheses):

if ($forumid == 19 OR $forumid == 21 OR $forumid == 23 OR $forumid == 24 OR $forumid == 27) AND ($bbuserinfo[usergroupid]!=6 OR $bbuserinfo[usergroupid]!=5 OR $bbuserinfo[usergroupid]!=7))
{

Keep in mind I don't know the first thing about coding so I'm hoping someone will know.

Polar
06-08-03, 03:34 PM
Hi Chicken.
I'd probably do something like this:


$cantpostforumid_array = array( 19, 21, 23, 24, 27 );

if ( in_array( $forumid, $cantpostforumid_array ) AND ($bbuserinfo[usergroupid]!=6 OR $bbuserinfo[usergroupid]!=5 OR $bbuserinfo[usergroupid]!=7))
{


Of the three examples you gave, I think the second one made the most sense.

Note that the two changes I made were
1) made $cantpostforumid an array, and renamed it $cantpostforumid_array
2) used the in_array (http://us4.php.net/manual/en/function.in-array.php) function to see if the $forumid variable is in the array.

Hope that helps,
Paul

Chicken
06-08-03, 03:44 PM
Thanks! I'll have to try it and see what works.