Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 03-24-2011, 05:13 AM
AFemaleProdigy's Avatar
AFemaleProdigy AFemaleProdigy is offline
 
Join Date: Mar 2006
Location: Murrells Inlet, SC
Posts: 216
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Display custom field in memberlist that contains multiple selections.

Yep, it's me again.

I have been using the code below to display custom fields in my new custom memberlist. It's been working great so far, but I just realized it doesn't work like I intended when the custom field values are from a multiple selection check box.

Code:
{vb:raw userinfo.field17}
So, if check box values are any combination of A,B,C,D - then that code outputs a number value according to the number value of boxes the user checked. How do I get it to output the actual textual value of the boxes checked by the user?

Example:

User can select any number of the following - Snacks, Breakfast, Lunch, Dinner

So if they check Breakfast and Dinner, that is what I want the output to be in my template. Instead, the code above will output the number assocciated with that option.

Thanks!
Reply With Quote
  #2  
Old 03-24-2011, 04:05 PM
OcR Envy's Avatar
OcR Envy OcR Envy is offline
 
Join Date: May 2008
Location: Boston
Posts: 248
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Custom Fields with more than one option are sorted based on the geometric formula. Meaning You would do something like this:

Userfield6(Radio, Select, Checkbox it doesn't matter)
Yes(1)
No(2)
Maybe(4)
Never(8)

PHP Code:
if($userfield['field6'] & 1)
  
$ans 'Yes';
elseif(
$userfield['field6'] & 2)
  
$ans 'No';
elseif(
$userfield['field6'] & 4)
  
$ans 'Maybe';
elseif(
$userfield['field6'] & 8)
  
$ans 'Never'
This continues on each time you multiply the number by itself
so to continue it would be 1,2,4,8,16,32,64 etc..
Reply With Quote
  #3  
Old 03-24-2011, 05:18 PM
AFemaleProdigy's Avatar
AFemaleProdigy AFemaleProdigy is offline
 
Join Date: Mar 2006
Location: Murrells Inlet, SC
Posts: 216
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I checked the values in the databse to make sure I had them correct, but this doesn't seem to work. My template is still outputting numbers instead of text values.

PHP Code:
if($userfield['field23'] & 1)
   
$ans 'Unknown';
 elseif(
$userfield['field23'] & 2)
   
$ans 'No Food';
 elseif(
$userfield['field23'] & 8)
   
$ans 'Breakfast';
 elseif(
$userfield['field23'] & 24)
   
$ans 'Lunch'
 elseif(
$userfield['field23'] & 32)
   
$ans 'Dinner';
 elseif(
$userfield['field23'] & 63)
   
$ans 'Snacks'
Code:
{vb:raw userinfo.field23}
Reply With Quote
  #4  
Old 03-24-2011, 05:58 PM
OcR Envy's Avatar
OcR Envy OcR Envy is offline
 
Join Date: May 2008
Location: Boston
Posts: 248
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I didn't convert it to template format

Something like this:

<vb:if condition="$userfield['field23'] & 1">
Yes
<vb:elseif condition="userfield['field23'] & 2">
No
<vb:endif>
Reply With Quote
  #5  
Old 11-27-2011, 09:45 PM
AFemaleProdigy's Avatar
AFemaleProdigy AFemaleProdigy is offline
 
Join Date: Mar 2006
Location: Murrells Inlet, SC
Posts: 216
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I am using this in my template and am getting an error when I try to save the template. Can anyone see a problem with this?

Code:
<vb:if condition="$userfield['field23'] & 1">
                            Unknown
                            <vb:elseif condition="userfield['field23'] & 2" />
                            No Food
                            <vb:elseif condition="userfield['field23'] & 24" />
                            Breakfast
                            <vb:elseif condition="userfield['field23'] & 32" />
                            Lunch
                            <vb:elseif condition="userfield['field23'] & 63" />
                            Dinner
                            <vb:elseif condition="userfield['field23'] & 8" />
                            Snacks
                            </vb:if>
Here is the error message:

The following error occurred when attempting to evaluate this template:
%1$s
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.
Reply With Quote
  #6  
Old 11-28-2011, 02:57 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

All your condition expressions except the first one are missing the $ in front of "userfield".
Reply With Quote
  #7  
Old 11-28-2011, 03:35 AM
AFemaleProdigy's Avatar
AFemaleProdigy AFemaleProdigy is offline
 
Join Date: Mar 2006
Location: Murrells Inlet, SC
Posts: 216
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I can't believe I didn't see that!! Lol!

However, I was finally able to save the template changes, but that code is not outputting anything. Grrr! This is what I have...

Code:
                  <vb:if condition="$userfield['field23'] & 1">
                            Unknown
                            <vb:elseif condition="$userfield['field23'] & 2" />
                            No Food
                            <vb:elseif condition="$userfield['field23'] & 24" />
                            Breakfast
                            <vb:elseif condition="$userfield['field23'] & 32" />
                            Lunch
                            <vb:elseif condition="$userfield['field23'] & 63" />
                            Dinner
                            <vb:elseif condition="$userfield['field23'] & 8" />
                            Snacks
                            </vb:if>
Also, is using elseif appropriate if there may be multiple options set? For example: Breakfast, Lunch, Dinner
Reply With Quote
  #8  
Old 11-28-2011, 03:42 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It might help to temporarily output the value of $userfield['field23'] to see what's going on.

That seems like a strange set of bits to check (normally they'd be 1, 2, 4, 8, 16, 32, 64, etc), but I don't know exactly how they're being used so what you have could be correct.
Reply With Quote
  #9  
Old 11-28-2011, 03:51 AM
AFemaleProdigy's Avatar
AFemaleProdigy AFemaleProdigy is offline
 
Join Date: Mar 2006
Location: Murrells Inlet, SC
Posts: 216
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I got those numbers from the database. They may have skipped around from me deleting and adding options. How can I temporarily output the values?
Reply With Quote
  #10  
Old 11-28-2011, 03:55 AM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by AFemaleProdigy View Post
I got those number from the database.
OK, but the 63 seems strange since 63 in binary is 111111, so that condition will be true if any of those bits are set. That would mean that the last "Snacks" condition would never be displayed. (Maybe you just want "==" instead of "&"?)

Quote:
How can I temporarily output the values?
I think you could just put {vb:raw userfield.field23} somewhere in the template.
Reply With Quote
Reply


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 12:33 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.03927 seconds
  • Memory Usage 2,273KB
  • Queries Executed 13 (?)
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
  • (4)bbcode_code
  • (2)bbcode_php
  • (2)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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_postinfo_query
  • fetch_postinfo
  • 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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete