Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 02-27-2003, 12:12 AM
inthezone inthezone is offline
 
Join Date: Feb 2003
Posts: 31
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default 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.
Reply With Quote
  #2  
Old 02-27-2003, 12:21 AM
lynda's Avatar
lynda lynda is offline
 
Join Date: Nov 2001
Posts: 31
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #3  
Old 02-27-2003, 12:21 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Will this work?

PHP Code:
if ($bbuserinfo['usergroupid']==or $bbuserinfo['usergroupid']==3
Reply With Quote
  #4  
Old 02-27-2003, 12:25 AM
inthezone inthezone is offline
 
Join Date: Feb 2003
Posts: 31
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Both methods work. Thanks for the help
Reply With Quote
  #5  
Old 02-27-2003, 10:09 AM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.";

Reply With Quote
  #6  
Old 02-27-2003, 10:29 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I was going to post that but since it was only 2, I went with the "or".
Reply With Quote
  #7  
Old 02-27-2003, 10:34 AM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

*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
Reply With Quote
  #8  
Old 02-27-2003, 10:47 AM
Boofo's Avatar
Boofo Boofo is offline
 
Join Date: Mar 2002
Location: Des Moines, IA (USA)
Posts: 15,776
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:20 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04090 seconds
  • Memory Usage 2,231KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (5)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (8)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete