Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 05-06-2006, 02:42 AM
lightnb lightnb is offline
 
Join Date: Dec 2005
Posts: 106
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Syntax: checking if multiple variables are set

I want a bit of code to run if $HD is set, $VD is also set, and $TD is NOT set.

Is there an easy way to do this?

I'm guessing it would be somthing like:

PHP Code:
if( isset( $GT2 and $VD !and $TD) ) {solve for $TD, and set $TD the answer}; 
Th PHP manual only gives an example of isset with one variable. Any help would be appreciated.

thanks,

Nick
Reply With Quote
  #2  
Old 05-06-2006, 02:50 AM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

More like ;

PHP Code:
if ( isset($GT2) and isset($VD) and !isset($TD) ) 
Reply With Quote
  #3  
Old 05-06-2006, 03:03 AM
lightnb lightnb is offline
 
Join Date: Dec 2005
Posts: 106
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks

Is this valid code to set $C equal to $A squared plus $B squared?

PHP Code:

if ( isset($A) and isset($B) and !isset($C) ) {$C=sqrt(($A*$A)+($B*$B));} 
Reply With Quote
  #4  
Old 05-06-2006, 03:11 AM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Um, did you mean set $C to the Square Root of $A squared plus $B squared
Reply With Quote
  #5  
Old 05-06-2006, 03:12 AM
lightnb lightnb is offline
 
Join Date: Dec 2005
Posts: 106
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

yeah, that was a typo...

I'm trying to calculate pythagreom therum. (sp?)
Reply With Quote
  #6  
Old 05-06-2006, 03:15 AM
Paul M's Avatar
Paul M Paul M is offline
 
Join Date: Sep 2004
Location: Nottingham, UK
Posts: 23,748
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Then yes, it looks valid.
Reply With Quote
  #7  
Old 05-06-2006, 03:18 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Yep! Personally I would pow(X, 2) to square it, but that doesn't matter. I gave it a trial run with 3, 4, and 5:
PHP Code:
<?php

$A 
3;
$B 4;

if (isset(
$A) and isset($B) and !isset($C))
{
    
$C sqrt(pow($A2) + pow($B2));
}

echo 
$C;

?>
Both methods gave the desired result of 5.
Reply With Quote
  #8  
Old 05-06-2006, 03:21 AM
lightnb lightnb is offline
 
Join Date: Dec 2005
Posts: 106
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks

Do you know if there's a command to check and see if any two variables out of a whole bunch of them isset?
Reply With Quote
  #9  
Old 05-06-2006, 03:34 AM
Adrian Schneider's Avatar
Adrian Schneider Adrian Schneider is offline
 
Join Date: Jul 2004
Posts: 2,528
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I highly doubt there is, but here is a quick one I wrote:

PHP Code:
<?php

function atLeastTwo($values)
{
    
$counter 0;
    foreach (
$values as $value)
    {
        if (
$value !== null)
        {
            
$counter++;
            if (
$counter == 2)
            {
                return 
true;
            }
        }
    }
    return 
false;
}

$a 1;
$b 2;

$values = @array($a$b$c);

if (
atLeastTwo($values))
{
    echo 
"Woot!  At least two are set!";
}
else
{
    echo 
"Phooey!  Less than two are set!";
}

?>
Just load the values into an array and pass it to the funtion, it will return the boolean result.
Reply With Quote
  #10  
Old 05-06-2006, 03:47 AM
lightnb lightnb is offline
 
Join Date: Dec 2005
Posts: 106
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks.

Does this work:

PHP Code:
//we place all the values into an array so we can run a function on them

$values = @array($HD$VD$TD$Dv$Dh$PC$FC$V$A$W$FA$MFv$MFh$GT1$GT2);


//we check to see if the user has filled in at least two variables

function atLeastTwo($values)
{
    
$counter 0;
    foreach (
$values as $value)
    {
        if (
$value !== null)
        {
            
$counter++;
            if (
$counter == 2)
            {
                return 
false;
            }
        }
    }
    return 
true;
}



if (
atLeastTwo($values))
{
    die 
"You Must fill in at least two fields before calculating";

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 10:41 PM.


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.04072 seconds
  • Memory Usage 2,261KB
  • Queries Executed 13 (?)
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
  • (6)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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_postinfo_query
  • fetch_postinfo
  • 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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete