vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Multiple Parameters for Conditionals (https://vborg.vbsupport.ru/showthread.php?t=49409)

inthezone 02-27-2003 12:12 AM

Multiple Parameters for Conditionals
 
I am writing a basic PHP conditional script that uses vBulletin's global.php to display different messages for different user levels. I want to have the same message display for those who have userlevels 1 and 3. I know how to write it with elseif syntax, like:

PHP Code:

if ($bbuserinfo['usergroupid']==1)
{
echo 
"You are not logged in, or you have not confirmed your e-mail address.";
}
elseif (
$bbuserinfo['usergroupid']==3
{
echo 
"You are not logged in, or you have not confirmed your e-mail address.";


is there a way to combine the two statements to eliminate the redundancy in that code, so that it will look something like:

PHP Code:

//This code leads to a parse error, but I am trying to do something to this effect.


if ($bbuserinfo['usergroupid']==1) or if ($bbuserinfo['usergroupid']==3)
{
echo 
"You are not logged in, or you have not confirmed your e-mail address.";



Edit-accidentally left out a bit of the code.

lynda 02-27-2003 12:21 AM

You should be able to do something like this without problems:

PHP Code:

if ($bbuserinfo['usergroupid']==|| $bbuserinfo['usergroup']==3
{
echo 
"You are not logged in, or you have not confirmed your e-mail address.";


The || stands for OR.

Boofo 02-27-2003 12:21 AM

Will this work?

PHP Code:

if ($bbuserinfo['usergroupid']==or $bbuserinfo['usergroupid']==3


inthezone 02-27-2003 12:25 AM

Both methods work. Thanks for the help

Xenon 02-27-2003 10:09 AM

yes, but you should prefer the or, its easier to read :)

also this method works and looks much better for more than two groups:

PHP Code:

if (in_array($bbuserinfo['usergroupid'], array(1,3)))
{
echo 
"You are not logged in, or you have not confirmed your e-mail address.";



Boofo 02-27-2003 10:29 AM

I was going to post that but since it was only 2, I went with the "or". ;)

Xenon 02-27-2003 10:34 AM

*gg*
even when there are just two it's shorter as you can see ;)

and so it's easy to add another group, so why don't just give him the solution for make it easy and fast ;)

Boofo 02-27-2003 10:47 AM

You're right, I should have gone the other route. I usually use the "or" if it is only 2 though. Habit more than anything, I guess. ;)


All times are GMT. The time now is 01:42 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.00931 seconds
  • Memory Usage 1,730KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (8)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete