MySQL Lookup on multiselect checkbox data

5 years 6 months ago #307545 by cpaschen
This is a bit 'side-related' to CB.
I have data in a field within the comprofiler table from a multiselect checkbox.

So the data looks something like this:

28|*|53|*|18

The data for this was provided from a lookup on an external table.

I need to 'convert' this data into the 'textual' labels which the user selected from; HOWEVER, I need to do it within a MYSQL query.

So the result of the query for this field needs to return something like:

President, Member, Accountant

Has anyone else every done this and made it work?

BTW ... I know how to handle this IF I could use PHP, but the project I'm working on right now doesn't have that ability. It must just be a MySQL query (and no mysql custom functions).

Any ideas would be appreciated.

Please Log in to join the conversation.

5 years 6 months ago #307555 by krileon
Replied by krileon on topic MySQL Lookup on multiselect checkbox data
Probably just need a subquery to lookup the label. Example as follows.

SELECT cb.`FIELD_NAME`
 , ( 
  SELECT GROUP_CONCAT( IF( fv.`fieldlabel` != '', fv.`fieldlabel`, fv.`fieldtitle` ) SEPARATOR ', ' )
  FROM `#__comprofiler_field_values` AS fv
  INNER JOIN `#__comprofiler_fields` AS f
  ON f.`fieldid` = fv.`fieldid`
  WHERE f.`name` = 'FIELD_NAME'
  AND FIND_IN_SET( fv.`fieldtitle`, REPLACE( cb.`FIELD_NAME`, '|*|', ',' ) ) != 0
 ) AS 'FIELD_NAME_labels'
 FROM `#__comprofiler` AS cb

Basically you've a subquery that splits the field into comma separated values for a lookup check in the field values table. Replace FIELD_NAME with the name of your field and #_ with your database prefix to give it a test. Probably better ways to do it, but I'm no database expert. If you're using language strings as labels they won't translate though as language strings are file based storage.


Kyle (Krileon)
Community Builder Team Member
Before posting on forums: Read FAQ thoroughly + Read our Documentation + Search the forums
CB links: Documentation - Localization - CB Quickstart - CB Paid Subscriptions - Add-Ons - Forge
--
If you are a Professional, Developer, or CB Paid Subscriptions subscriber and have a support issue please always post in your respective support forums for best results!
--
If I've missed your support post with a delay of 3 days or greater and are a Professional, Developer, or CBSubs subscriber please send me a private message with your thread and will reply when possible!
--
Please note I am available Monday - Friday from 8:00 AM CST to 4:00 PM CST. I am away on weekends (Saturday and Sunday) and if I've missed your post on or before a weekend after business hours please wait for the next following business day (Monday) and will get to your issue as soon as possible, thank you.
--
My role here is to provide guidance and assistance. I cannot provide custom code for each custom requirement. Please do not inquire me about custom development.

Please Log in to join the conversation.

5 years 6 months ago #307646 by cpaschen
Replied by cpaschen on topic MySQL Lookup on multiselect checkbox data
Thanks. I tried doing that but the SQL was just getting too complex to maintain (multiple multi-select fields in the query), so I've just decided to use a CB List to handle the task.

However, it would be really helpful if the CB Lists had the ability to export the resulting list as a CSV (or other format) for use offline.

Please Log in to join the conversation.

Moderators: beatnantkrileon
Time to create page: 0.211 seconds

Facebook Twitter LinkedIn