I am trying to setup an advanced list sorting query that lists a few people by a specific field value and the rest by name .
By the info supplied on the configuration page for the advanced sorting you just need to supply a valid ORDER BY statement.
When I put in a ORDER BY statement that has been confirmed to work in mysql I just get the sql error "1064 You have an error in your SQL syntax" when going to list in the front end.
Below is the order by statement I put into the advanced sort configuration.
Code:
ORDER BY CASE
WHEN ue.cb_position LIKE "President%" THEN 1
WHEN ue.cb_position LIKE "Vice President%" THEN 2
WHEN ue.cb_position LIKE "Secretary%" THEN 3
WHEN ue.cb_position LIKE "Tresurer%" THEN 4
WHEN ue.cb_position LIKE "Ordinary Committee Member%" THEN 5
ELSE 6
END, u.name
This is the full query that works in mysql
Code:
SELECT DISTINCT ue.*, u.*, '' AS 'NA'
FROM j25_users u JOIN j25_user_usergroup_map g ON g.`user_id` = u.`id` JOIN j25_comprofiler ue ON ue.`id` = u.`id`
WHERE u.block = 0 AND ue.approved = 1 AND ue.confirmed = 1 AND ue.banned = 0 AND g.group_id IN (2, 3) AND ( `cb_committeemember` = '1' )
ORDER BY CASE
WHEN ue.cb_position LIKE "President%" THEN 1
WHEN ue.cb_position LIKE "Vice President%" THEN 2
WHEN ue.cb_position LIKE "Secretary%" THEN 3
WHEN ue.cb_position LIKE "Tresurer%" THEN 4
WHEN ue.cb_position LIKE "Ordinary Committee Member%" THEN 5
ELSE 6
END, u.name
Am I doing it wrong?
Last edit: 9 years 3 weeks ago by krileon. Reason: Added [SOLVED] tag to subject
Don't include ORDER BY as that's added in code resulting in "ORDER BY ORDER BY" causing your SQL syntax error.
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.