vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Display custom field in memberlist that contains multiple selections. (https://vborg.vbsupport.ru/showthread.php?t=260867)

AFemaleProdigy 03-24-2011 05:13 AM

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

OcR Envy 03-24-2011 04:05 PM

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

AFemaleProdigy 03-24-2011 05:18 PM

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}

OcR Envy 03-24-2011 05:58 PM

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>

AFemaleProdigy 11-27-2011 09:45 PM

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.

kh99 11-28-2011 02:57 AM

All your condition expressions except the first one are missing the $ in front of "userfield".

AFemaleProdigy 11-28-2011 03:35 AM

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

kh99 11-28-2011 03:42 AM

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.

AFemaleProdigy 11-28-2011 03:51 AM

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?

kh99 11-28-2011 03:55 AM

Quote:

Originally Posted by AFemaleProdigy (Post 2272612)
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.


All times are GMT. The time now is 02:02 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.01068 seconds
  • Memory Usage 1,757KB
  • 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
  • (4)bbcode_code_printable
  • (2)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)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