vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   Using an array in an if statement.... (https://vborg.vbsupport.ru/showthread.php?t=48419)

Link14716 02-01-2003 11:32 PM

Using an array in an if statement....
 
I want to know how to use several values, seperated by commas, in an if statement. This is probably very basic, but I need to know. Thanks :)

mr e 02-02-2003 12:36 AM

can you be more specific?

Link14716 02-02-2003 12:42 AM

Say a variable contains this:
Code:

5,6,7,10,56,63
I want to drop an if statement, checking each of them.
Code:

if ($bbuserinfo[usergroupid]=="5" OR $bbuserinfo[usergroupid]=="6" OR $bbuserinfo[usergroupid]=="7" OR $bbuserinfo[usergroupid]=="10" OR $bbuserinfo[usergroupid]=="56" OR $bbuserinfo[usergroupid]=="63") {
How would I make it so that all of that is combined into something like
Code:

if ($bbuserinfo[usergroupid]==$variable) {
Where variable has all of those values mentioned above and actualy work?

mr e 02-02-2003 01:06 AM

well this is what i would do...

PHP Code:

$vars "1,2,4,5,9";
$var explode (","$vars);

if (
preg_match($var$bbuserinfo[userid])) {
  do 
code here;
} else {
       
more code here;


i think that should work

Xenon 02-02-2003 11:42 AM

Link, you should read more of my posts, i use the correct code very often:

PHP Code:

if(in_array($bbuserinfo[usergroupid], array(5,6,7,10,56,63
)) {




Link14716 02-02-2003 05:33 PM

That's what it is. I just didn't remember it becuase I haven't had any need for it until now. ;)

Thanks. :)

mr e 02-02-2003 05:56 PM

i'll have to remember that :D

Link14716 02-02-2003 07:02 PM

In forumdisplay.php, I have this code:
PHP Code:

if (in_array($bbuserinfo[usergroupid], array($privateusergroupable))) {
$getthreadids=$DB_site->query("
    SELECT
    "
.iif($sortfield=="voteavg",$votequery,"")."
        thread.threadid
    FROM thread
    WHERE thread.forumid = 
$foruminfo[forumid]
        AND thread.sticky=0
    
$datecut
    
$limitothers
      ORDER BY sticky DESC, 
$sortfield $sqlsortorder
      LIMIT "
.($sel_limitlower-1).",$perpage");
} else {
$getthreadids=$DB_site->query("
    SELECT
    "
.iif($sortfield=="voteavg",$votequery,"")."
        thread.threadid
    FROM thread
    WHERE thread.forumid = 
$foruminfo[forumid]
        AND thread.sticky=0
        AND thread.visible=1
    
$datecut
    
$limitothers
      ORDER BY sticky DESC, 
$sortfield $sqlsortorder
      LIMIT "
.($sel_limitlower-1).",$perpage");


But this doesn't seem to be working - it doesn't show the invisible threads, even though usergroupid 6 is in the array. Any ideas?

Furthermore, if the variable $allowusercreateprivate is set to 1, I want it to get all of that user's threads even if visible!=1. Any ideas on that?

mr e 02-02-2003 07:20 PM

try this

PHP Code:

if (in_array($bbuserinfo[usergroupid], $privateusergroupable)) {
$getthreadids=$DB_site->query("
    SELECT
    "
.iif($sortfield=="voteavg",$votequery,"")."
        thread.threadid
    FROM thread
    WHERE thread.forumid = 
$foruminfo[forumid]
        AND thread.sticky=0
    
$datecut
    
$limitothers
      ORDER BY sticky DESC, 
$sortfield $sqlsortorder
      LIMIT "
.($sel_limitlower-1).",$perpage");
} else {
$getthreadids=$DB_site->query("
    SELECT
    "
.iif($sortfield=="voteavg",$votequery,"")."
        thread.threadid
    FROM thread
    WHERE thread.forumid = 
$foruminfo[forumid]
        AND thread.sticky=0
        AND thread.visible=1
        "
.iif($allowusercreateprivate==1,"AND thread.visible=0","")."
    
$datecut
    
$limitothers
      ORDER BY sticky DESC, 
$sortfield $sqlsortorder
      LIMIT "
.($sel_limitlower-1).",$perpage");


not sure if this'll work though

Link14716 02-02-2003 07:28 PM

Nope...

Code:

Warning: Wrong datatype for second argument in call to in_array() in /home/sites/site68/web/forums/forumdisplay.php on line 493

Warning: Missing argument 2 for iif() in /home/sites/site68/web/forums/admin/functions.php on line 618

Warning: Missing argument 3 for iif() in /home/sites/site68/web/forums/admin/functions.php on line 618


mr e 02-02-2003 07:34 PM

oh well, i didn't now how those if querys work anyways, just a stab in the dark :D

Xenon 02-03-2003 03:12 PM

link it seems $privateusergroupable is not an array but a string..., instead of that:
PHP Code:

if (in_array($bbuserinfo[usergroupid], array($privateusergroupable))) { 

try that:
PHP Code:

eval("$privatearray = array(".$privateusergroupable.");");
if (
in_array($bbuserinfo[usergroupid], array($privatearray))) { 


fla5h 02-03-2003 06:41 PM

Sorry to jump on this thread but how would I alter this

PHP Code:

$DB_site->query_first("SELECT username,userid FROM user WHERE userid=$vouchid AND usergroupid!=5"); 

So that I can input a variable in the admin options say $banuserid and the values of 5,1,2

PHP Code:

$DB_site->query_first("SELECT username,userid FROM user WHERE userid=$vouchid AND usergroupid!=$banuserid"); 


Xenon 02-04-2003 04:17 PM

its this:
PHP Code:

$DB_site->query_first("SELECT username,userid FROM user WHERE userid=$vouchid AND usergroupid NOT IN ($banuserid)"); 


fla5h 02-05-2003 07:20 PM

Worked a treat. Thanks once again Xenon.


All times are GMT. The time now is 10:54 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.01238 seconds
  • Memory Usage 1,773KB
  • 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
  • (4)bbcode_code_printable
  • (9)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (15)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