Skip to Content Skip to Menu

[SOLVED] How to get values from a query checkbox field in autoactions

  • carin
  • carin
  • OFFLINE
  • Posts: 417
  • Thanks: 18
  • Karma: 0
10 years 8 months ago - 10 years 8 months ago #241454 by carin
I set up a query checkbox field "cb_mycatids" which stores category IDs like 23|*|26|*|98 in the db.

In an autoaction type "query" I need to put these category IDs into a query like this:
Code:
UPDATE #__jdownloads_cats SET cat_description='[name]' WHERE cat_id IN ([cb_mycatids]);

Since the delimiter is |*| and not a comma I need to substitute this so I can use the values in the IN statement. How would I do this?

CB 2.0
Last edit: 10 years 8 months ago by krileon.

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48477
  • Thanks: 8281
  • Karma: 1443
10 years 8 months ago - 10 years 8 months ago #241480 by krileon
You should be able to just replace the |*| delimiter with a comma. Example as follows.

Code:
REPLACE( '[cb_mycatids]', '|*|', ',' )

Next you need to use FIND_IN_SET instead of IN, because IN can't parse a string of comma separated values. Example as follows.

Code:
FIND_IN_SET( `cat_id`, REPLACE( '[cb_mycatids]', '|*|', ',' ) ) > 0

Information on FIND_IN_SET can be found below.

dev.mysql.com/doc/refman/5.0/en/string-functions.html#function_find-in-set


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.
Last edit: 10 years 8 months ago by krileon.
The following user(s) said Thank You: carin

Please Log in or Create an account to join the conversation.

  • carin
  • carin
  • OFFLINE
  • Posts: 417
  • Thanks: 18
  • Karma: 0
10 years 8 months ago #241511 by carin
Thanks for the hint, spot on! That is what I could not solve.

I know it is not the purpose of this forum to teach us users SQL and PHP. But I was not even aware of that I can use PHP in that way in the query field.

Thank you very much. Outstanding support!

CB 2.0
The following user(s) said Thank You: krileon

Please Log in or Create an account to join the conversation.

  • nant
  • nant
  • OFFLINE
  • Posts: 12339
  • Thanks: 1467
  • Karma: 877
10 years 8 months ago #241525 by nant

carin wrote:
Outstanding support!


Great Job Kyle!

(I am smelling a nice review coming on our JED Community Builder listing ;-) )
The following user(s) said Thank You: krileon

Please Log in or Create an account to join the conversation.

  • carin
  • carin
  • OFFLINE
  • Posts: 417
  • Thanks: 18
  • Karma: 0
10 years 8 months ago #241526 by carin

... a nice review coming ...


... is on its way, already done yesterday but I dont know if it will pass the JED editor with all the praising ;)

CB 2.0
The following user(s) said Thank You: krileon

Please Log in or Create an account to join the conversation.

  • krileon
  • krileon
  • ONLINE
  • Posts: 48477
  • Thanks: 8281
  • Karma: 1443
10 years 8 months ago #241545 by krileon

I know it is not the purpose of this forum to teach us users SQL and PHP. But I was not even aware of that I can use PHP in that way in the query field.

You're actually using SQL in SQL. SQL has a pretty awesome set of functions that can mimic a lot of PHPs usage (even REGEX!). The below is a nice reference of what functions are likely available for most MYSQL installs.

dev.mysql.com/doc/refman/5.6/en/functions.html

The above gives a chapter like list so you can see functions relevant to strings only, dates only, etc.. the below is a full list of all the functions together.

dev.mysql.com/doc/refman/5.6/en/func-op-summary-ref.html

Also worth noting I've a Code Fieldtype plugin planned after CB 2.0 that outputs PHP as field value. It'll kinda function the same way the Code action does in CB Auto Actions. So that's something to look forward to if you're wanting to use PHP directly.


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.
The following user(s) said Thank You: nant, carin

Please Log in or Create an account to join the conversation.

Moderators: beatnantkrileon
Powered by Kunena Forum