vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Simple IF Question (https://vborg.vbsupport.ru/showthread.php?t=217221)

Cledus James 06-26-2009 11:01 PM

Simple IF Question
 
Ok, Im basically editing my postbit and I need to know how to write an IF statement based on a registration question (user profile field).

The question is "What system do you primarly play on". Its a radio box with 2 choices: "Xbox 360 and Playstation 3". That question is followed by another single line textbox question asking for either Xbox Gamertag or PSN ID. Now from there Im trying to edit my postbit to display either their xbox gamertag or psn id depending on how thy answered the question.

So, I need to know how to write the IF statement in the postbit. I need a statement like:

<If condition = "[fieldXX] = Xbox 360">

Can anyone help me with the proper code to write out to basically say "if the answer to feildX is Xbox 360". I know what to do from there but I havnt edited or seen any code dealing with an IF based on a user profile field answer.

Thank you in advance for taing the time togive me any input you can.

HMBeaty 06-26-2009 11:06 PM

HTML Code:

<if condition="post['fieldxxx']"><img src="path.to.image/$post[fieldxxx].gif" alt="" />
HTML Code:

</if>
Now, the images you're using for "fieldxxx" must be named, exactly how you have them named in the AdminCP.

For example:
- AdminCP = "Xbox 360" (without the quotes)
- Image = "Xbox 360.gif" (without the quotes)

Cledus James 06-28-2009 02:32 PM

What I need though is a IF statement dependng on the answer to the question, something like:

HTML Code:

<if condition="post['fieldxxx'] ='Xbox 360'"><img src="path.to.image/$post[fieldxxx].gif" alt="" />
But of course "= 'Xbox 360'" doesnt work.

Thank you for your input though, but I need an IF that says "if the answer is A, display this image, else if the answer is B display this image".

Webmaster961 06-28-2009 03:37 PM

You need to use == and not = inside if statements.

As you want to compare right hand side with left hand side, and not set right hand side to left hand side.

Example:

a = 5 + 6;

This means that a is set to be 5+6 which is 11, so a will be 11

a == 5 + 6;

This checks the value of a to see if it is the value of 5 + 6.

So you should try this:

HTML Code:

<if condition="post['fieldxxx'] == 'Xbox 360' ">
    <img src="path.to.image/$post[xbox].gif" alt="" />
<else /> <!-- User must have picked PS3 -->
    <img src="path.to.image/$post[ps3].gif" alt="" />
</if>

Of course you could also incorporate more platforms like this:

HTML Code:

<if condition="post['fieldxxx'] == 'Xbox 360' ">
    <img src="path.to.image/$post[xbox].gif" alt="" />
<else />
    <if condition="post['fieldxxx'] == 'PS3' ">
        <img src="path.to.image/$post[ps3].gif" alt="" />
    <else />
        <img src="path.to.image/$post[pc].gif" alt="" />
    </if>
</if>

That should work, but I haven't tested it.

Found it on the vBulletin Manual HERE

Cledus James 06-28-2009 04:09 PM

Thank you for your reply and thetime to took to answer my question. I'll test it out this week.

Cledus James 06-30-2009 11:16 PM

I tested the code and it gave me an error message:

Quote:

The following error occurred when attempting to evaluate this template:

Parse error: parse error, unexpected '[' in nameofsite/forums/includes/adminfunctions_template.php(3729) : eval()'d code on line 74

This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish.
Line 74 is the first IF statement. The code I used was:

HTML Code:

<if condition="post['field9'] == 'Xbox 360' ">
                        <td class="alt2" align="left" valign="top"><iframe src="http://gamercard.xbox.com/$post[field10].card" scrolling="no" frameBorder="0" height="95" width="204">$post[field10]</iframe></td>
                        </if>
                        <if condition="post['field9'] == 'Playstation 3' ">
                        <td class="alt2" align="left" valign="top"><a href="http://www.us.playstation.com/PSN/Users/$post[field33]"><img src="http://pid.us.playstation.com/user/$post[field33].jpg" width="235" height="149" border="0" /></a></td>
                        </if>

I also tested it with just IF statements and it still didnt work on so the problem is with them, not the output. I also tested the output of
PHP Code:

$post[field9

and it had the right anseers, Xbox 360 or Playstation 3.

Can someone help me out, doesn seem like that hard of a question, lol. Baically just need something along the lines of:
HTML Code:

<if condition="post['field9'] == 'Xbox 360' ">
Field9 is is a user profile field question with radio buttons with 2 selections as answers: Xbox 360 or Playstation 3.

Thanks goes to those who take the time to reply to a VB newbie.

HMBeaty 06-30-2009 11:31 PM

Try this
HTML Code:

<if condition="post[field9] == 'Xbox 360' ">
        <td class="alt2" align="left" valign="top">
                <iframe src="http://gamercard.xbox.com/$post[field10].card" scrolling="no" frameBorder="0" height="95" width="204">$post[field10]                </iframe>
        </td>
</if>
<if condition="post[field9] == 'Playstation 3' ">
        <td class="alt2" align="left" valign="top">
                <a href="http://www.us.playstation.com/PSN/Users/$post[field33]">
                <img src="http://pid.us.playstation.com/user/$post[field33].jpg" width="235" height="149" border="0" alt="" />
                </a>
        </td>
</if>


Cledus James 07-01-2009 03:58 AM

Same error:

HTML Code:

The following error occurred when attempting to evaluate this template:

Parse error: parse error, unexpected '[' in nameofsite/forums/includes/adminfunctions_template.php(3729) : eval()'d code on line 75

This is likely caused by a malformed conditional statement. It is highly recommended that you fix this error before continuing, but you may continue as-is if you wish.

Line 75 is the first IF statement. Anymore ideas? lol

toonysnn 07-01-2009 04:03 AM

Quote:

Originally Posted by Redlinemotorsports (Post 1840440)
Try this
HTML Code:

<if condition="post[field9] == 'Xbox 360' ">
    <td class="alt2" align="left" valign="top">
        <iframe src="http://gamercard.xbox.com/$post[field10].card" scrolling="no" frameBorder="0" height="95" width="204">$post[field10]        </iframe>
    </td>
</if>
<if condition="post[field9] == 'Playstation 3' ">
    <td class="alt2" align="left" valign="top">
        <a href="http://www.us.playstation.com/PSN/Users/$post[field33]">
        <img src="http://pid.us.playstation.com/user/$post[field33].jpg" width="235" height="149" border="0" alt="" />
        </a>
    </td>
</if>


Almost right.
HTML Code:

<if condition="$post[field9] == 'Xbox 360' ">
    <td class="alt2" align="left" valign="top">
        <iframe src="http://gamercard.xbox.com/$post[field10].card" scrolling="no" frameBorder="0" height="95" width="204">$post[field10]        </iframe>
    </td>
</if>
<if condition="$post[field9] == 'Playstation 3' ">
    <td class="alt2" align="left" valign="top">
        <a href="http://www.us.playstation.com/PSN/Users/$post[field33]">
        <img src="http://pid.us.playstation.com/user/$post[field33].jpg" width="235" height="149" border="0" alt="" />
        </a>
    </td>
</if>


HMBeaty 07-01-2009 04:20 AM

AH!!! I see what I did!! I can't believe I missed that!


All times are GMT. The time now is 12:39 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.01271 seconds
  • Memory Usage 1,766KB
  • 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
  • (11)bbcode_html_printable
  • (1)bbcode_php_printable
  • (2)bbcode_quote_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