vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   conditional query (https://vborg.vbsupport.ru/showthread.php?t=65475)

sabret00the 05-24-2004 01:13 PM

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 


Xenon 05-24-2004 01:57 PM

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 


sabret00the 05-24-2004 01:59 PM

but if i put them additionals curly brackets in, won't i close the conditionals? before it's acheive what i want it to?

sabret00the 05-24-2004 02:06 PM

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. 


Xenon 05-24-2004 02:36 PM

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

sabret00the 05-24-2004 03:57 PM

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?

Xenon 05-24-2004 05:20 PM

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 


Velocd 05-24-2004 05:24 PM

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 


sabret00the 05-24-2004 08:59 PM

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.

Velocd 05-24-2004 11:51 PM

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)




All times are GMT. The time now is 07:01 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.01318 seconds
  • Memory Usage 1,785KB
  • 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
  • (7)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)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
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete