Skip to Content Skip to Menu

CB Query field

  • rbuelund
  • rbuelund
  • OFFLINE
  • Posts: 565
  • Thanks: 40
  • Karma: 4
7 years 5 months ago #293746 by rbuelund
CB Query field was created by rbuelund
I want to make a single select query field where I can choose users from a certain usergroup:

SELECT `a.id`,`a.name`,`b.user_id`, `b.group_id` FROM `#__users`, `a` INNER JOIN `#__user_usergroup_map`, `b` ON `a.id` = `b.user_id` WHERE `b.group_id` LIKE `17` ORDER `a.name` ASC

The above works in a Joomla db query, but it throws an error in the CB query field - why ?

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48449
  • Thanks: 8280
  • Karma: 1443
7 years 5 months ago - 7 years 5 months ago #293756 by krileon
Replied by krileon on topic CB Query field
That query is not valid. It has syntax errors and escaping errors. Joomla likely is just not throwing an error. CB does not suppress errors as it's bad practice and prevents you from knowing when something is wrong. The below is valid.

Code:
SELECT a.`id`, a.`name`, b.`user_id`, b.`group_id` FROM `#__users` AS `a` INNER JOIN `#__user_usergroup_map` AS `b` ON a.`id` = b.`user_id` WHERE b.`group_id` = 17 ORDER BY a.`name` ASC

See the below for SQL resources on how to write valid SQL.

www.w3schools.com/sql/default.asp
dev.mysql.com/doc/refman/5.6/en/tutorial.html


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: 7 years 5 months ago by krileon. Reason: typo

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

  • rbuelund
  • rbuelund
  • OFFLINE
  • Posts: 565
  • Thanks: 40
  • Karma: 4
7 years 5 months ago #293760 by rbuelund
Replied by rbuelund on topic CB Query field
Thank you!

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

Moderators: beatnantkrileon
Powered by Kunena Forum