Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 05-24-2004, 01:13 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default conditional query

can i do?

PHP Code:
if (whatever == 1) { main condition
  
if (isset(submit && id)) { //starts main form process
  
} else { main conditional alternative
  
if (isset(submit && id)) { //do form this way
  
}
  
// rest of main form process
  
  
  
  
// close main form process conditional 
Reply With Quote
  #2  
Old 05-24-2004, 01:57 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

i think you forgot a { } pair

PHP Code:
if (whatever == 1)
main condition
  
if (isset(submit && id)) { //starts main form process
  

}
else
{  
main conditional alternative
  
if (isset(submit && id)) { //do form this way
  
}
  
// rest of main form process
  
  
  
// close main form process conditional 
Reply With Quote
  #3  
Old 05-24-2004, 01:59 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

but if i put them additionals curly brackets in, won't i close the conditionals? before it's acheive what i want it to?
Reply With Quote
  #4  
Old 05-24-2004, 02:06 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

heres an example of the code i'm trying to ask if will work or not
PHP Code:
             if (isset($conf_userid)) { // signed in member
                 
$conf_userid $bbuserinfo[userid];
             } else { 
// guest
                 
$conf_userid "NULL";
             }
 
 
// this is the bit i'm asking about
         
if (vboptions(guest confession == 1)) { this will allow guests to confess
             
if ('confess' && $confession_submit && trim($message) != '' && $bbuserinfo[userid] >= 0) { guests can confess
         
} else {
             if (
'confess' && $confession_submit && trim($message) != '' && $bbuserinfo[userid] > 0) { members only can confess
         

 
// above is the bit i'm asking about
 
                 
$flood $DB_site->query("
                     SELECT timestamp 
                     FROM confessions 
                     ORDER BY timestamp
                     WHERE userid = 
$bbuserinfo[userid]
                     DESC LIMIT 1
                 "
);
                 
$check $DB_site->fetch_array($flood);
         
                 if (empty(
$nousername)) {
                     
$conf_userid "$bbuserinfo[userid]";
                 } else {
                     
$conf_userid "NULL";
                 }
 
                 if ((
time() - $check[timestamp]) <= 15) {
                     eval(
"standarderror(\"".fetch_template("confession_error_flood")."\");");
                 }
                     
$DB_site->query("
                         INSERT INTO confessions SET
                         text = '"
.addslashes($message)."',
                         userid = '
$conf_userid',
                         timestamp = '"
.time()."'
                     "
);
 } 
// guest or members only conditional ends here. 
Reply With Quote
  #5  
Old 05-24-2004, 02:36 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

if you don't close the brackets, the else will be regarded to the inner if's and not to the outer if as you want to have
Reply With Quote
  #6  
Old 05-24-2004, 03:57 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

ok sorry to bother you but i don't get it, just edited my last post for a clarity, basically the conditional starts inside of the if/else and ends outside of it. yet if i close them, then it's not gonna perform what i'm asking it to do?
Reply With Quote
  #7  
Old 05-24-2004, 05:20 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

now you have confused me.....

i don't get what you want, but from what you said before, that code is correct:
PHP Code:
// this is the bit i'm asking about
    
if (vboptions(guest confession == 1))
    { 
this will allow guests to confess
        
if ('confess' && $confession_submit && trim($message) != '' && $bbuserinfo[userid] >= 0)
        { 
guests can confess
            
        
}
    }
    else
    {
        if (
'confess' && $confession_submit && trim($message) != '' && $bbuserinfo[userid] > 0)
        { 
members only can confess
        
        
}
    } 
// above is the bit i'm asking about 
Reply With Quote
  #8  
Old 05-24-2004, 05:24 PM
Velocd's Avatar
Velocd Velocd is offline
 
Join Date: Mar 2002
Location: CA University
Posts: 1,696
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I've clarified your code.

It's extremely recommended to put brackets for if, else, loops, and functions under the statement. Also, when verifying if a variable exists, use isset(). If you just want to see if a variable has a value, check with the ! (bang) operator in a boolean statement. For strings, use empty().

Here is your code. I'm not sure what you're trying to achieve with the empty IFs, but you were missing the last bracket.

PHP Code:
if (!$conf_userid
{
    
$conf_userid $bbuserinfo['userid'];

else 
{
    
$conf_userid "NULL";
}

if (
vboptions(guest confession == 1)) 
{
    if (
'confess' && $confession_submit && trim($message) && $bbuserinfo[userid] >= 0)
    {
        
// whatever you're trying to achieve
    

    else 
    {
        if (
'confess' && $confession_submit && trim($message) && $bbuserinfo[userid] > 0)
        {
            
// whatever you're trying to achieve
        
}
        
            
$flood $DB_site->query("
                SELECT timestamp
                FROM confessions
                ORDER BY timestamp
                WHERE userid = 
$bbuserinfo[userid]
                DESC LIMIT 1
            "
);
            
            
$check $DB_site->fetch_array($flood);
        
            if (empty(
$nousername))
            {
                
$conf_userid "$bbuserinfo[userid]";
            } 
            else 
            {
                
$conf_userid "NULL";
            }

            if ((
time() - $check[timestamp]) <= 15
            {
                eval(
"standarderror(\"".fetch_template("confession_error_flood")."\");");
            }
            
            
$DB_site->query("
                INSERT INTO confessions SET
                text = '"
.addslashes($message)."',
                userid = '
$conf_userid',
                timestamp = '"
.time()."'
            "
);
    }
}  
// was missing 
Reply With Quote
  #9  
Old 05-24-2004, 08:59 PM
sabret00the's Avatar
sabret00the sabret00the is offline
 
Join Date: Jan 2003
Location: London
Posts: 5,268
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

thank you all, it's very much appreciated, velo, what i was trying to acheive started with the $flood variable and ended with the "INSERT INTO confessions SET..." bit basically i was trying to find out if i needed to repeat the whole code or if i could just use the conditional based on an admin cp option of letting guests confess or not.
Reply With Quote
  #10  
Old 05-24-2004, 11:51 PM
Velocd's Avatar
Velocd Velocd is offline
 
Join Date: Mar 2002
Location: CA University
Posts: 1,696
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Just a minor correction..

I had:
PHP Code:
if (!$conf_userid)

The ! (bang) operator, which could literally be translated to "not", is equivalent to empty().

Not using ! is equivalent to !empty(), or just placing a variable between the () in a statement.

The code should have been:

PHP Code:
if ($conf_userid)

Reply With Quote
Reply


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 08:52 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.04306 seconds
  • Memory Usage 2,308KB
  • 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
  • (7)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_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