Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
  #1  
Old 05-28-2008, 03:55 AM
Ark del KAOS's Avatar
Ark del KAOS Ark del KAOS is offline
 
Join Date: Sep 2002
Location: Madrid, Spain
Posts: 27
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default It's this a suicidal code?: Maybe I'm going to kill my own DB

This is the code...
Code:
<if condition="$post['field18'] == 'TEXT-'">
    CODE A
<else />
<if condition="$post['field18'] == 'TEXT-B'">
    CODE B
<else />
<if condition="$post['field18'] == 'TEXT-C'">
    CODE C
<else />
<if condition="$post['field18'] == 'CODED'">
    CODE D
<else />
......
It's like this, but so many times more. Around 50 times.

When I first think of this...well, I think it'll make only one DB call for $post['field18'], and then compare the results with the IF possibilities.
But maybe not.

If I do this...I'm cutting my own throat? O o''
(If it's one db call for every one posibility....YES IT IS )

Maybe it's too obvious, but...well....I need to know it Sorry!
And thanks!
Reply With Quote
  #2  
Old 05-28-2008, 04:10 AM
Attilitus's Avatar
Attilitus Attilitus is offline
 
Join Date: Mar 2005
Posts: 393
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

While I"m sure there is a better way to do whatever your trying to do... that code will not break anything.

You cannot execute queries from the template, you can only access variables that have already been created by the script. The array $post already includes all of the values for that array including $post['field18']. The query that populates that array will be executed whether or not you use the variable $post['field18'] in the template.
Reply With Quote
  #3  
Old 05-28-2008, 04:12 AM
Wired1's Avatar
Wired1 Wired1 is offline
 
Join Date: Nov 2003
Location: Orlando, FL, USA
Posts: 1,361
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Use a SWITCH instead of 50 IF statements. Use this in a plugin of course, as it's PHP.
Example:
PHP Code:
switch ($post['field18'])
{
    case 
'TEXT A':
    {
        <
CODE>
        break;
    }
    case 
'TEXT B':
    {
        <
CODE>
        break;
    }
    case 
'TEXT C':
    {
        <
CODE>
        break;
    }
    default:
    {
        <
CODE>
    }

Reply With Quote
  #4  
Old 05-28-2008, 07:13 AM
Dismounted's Avatar
Dismounted Dismounted is offline
 
Join Date: Jun 2005
Location: Melbourne, Australia
Posts: 15,047
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Use Wired1's method, and assign your data to a variable. Use that variable in your template.
Reply With Quote
  #5  
Old 05-28-2008, 02:03 PM
Ark del KAOS's Avatar
Ark del KAOS Ark del KAOS is offline
 
Join Date: Sep 2002
Location: Madrid, Spain
Posts: 27
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you very much! ^ ^

You know when you don't understand what happening, and starts to doubt about everything? ¬ ¬
Well, at least I'll never going to doubt about it again.
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 03:29 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.04010 seconds
  • Memory Usage 2,194KB
  • 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
  • (1)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (5)post_thanks_box
  • (5)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (5)post_thanks_postbit_info
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)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