vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   It's this a suicidal code?: Maybe I'm going to kill my own DB (https://vborg.vbsupport.ru/showthread.php?t=180748)

Ark del KAOS 05-28-2008 03:55 AM

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 :eek:)

Maybe it's too obvious, but...well....I need to know it :) Sorry!
And thanks!

Attilitus 05-28-2008 04:10 AM

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.

Wired1 05-28-2008 04:12 AM

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>
    }



Dismounted 05-28-2008 07:13 AM

Use Wired1's method, and assign your data to a variable. Use that variable in your template.

Ark del KAOS 05-28-2008 02:03 PM

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.


All times are GMT. The time now is 08: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.02951 seconds
  • Memory Usage 1,721KB
  • 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
  • (1)bbcode_code_printable
  • (1)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (5)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