Log in

View Full Version : Simple IF Question


Cledus James
06-26-2009, 11:01 PM
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
<if condition="post['fieldxxx']"><img src="path.to.image/$post[fieldxxx].gif" alt="" /></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:

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

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

<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 (http://www.vbulletin.com/docs/html/template_conditionals)

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:

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:

<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 $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:
<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<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:

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
Try this<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.<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!

Cledus James
07-01-2009, 04:26 AM
Wow. It worked. Thanks for all the help guys!

HMBeaty
07-01-2009, 04:52 AM
No probably, sorry we were running in circles with this one. I can't believe I missed that, lol