Skip to Content Skip to Menu

Sort List

  • galanopd
  • galanopd
  • OFFLINE
  • Posts: 374
  • Thanks: 49
  • Karma: 8
3 years 2 weeks ago - 3 years 2 weeks ago #326897 by galanopd
Replied by galanopd on topic Sort List
Can you please have a look at the query below and tell me why it throws an error while on fiddle www.db-fiddle.com/f/gi6vnWVYQddvXZt1vpxw2L/5 seem to work?
Code:
SELECT sub.`parent_plan`, sub.`plan_id` FROM `#__cbsubs_subscriptions` AS sub JOIN `#__users` AS u ON sub.`user_id` = u.`id` JOIN `#__comprofiler` AS ue ON sub.`user_id` = ue.`user_id` WHERE sub.`status` = 'A' ORDER BY FIELD(sub.`plan_id`,14,35,34,33,32,31,17,16,15,11,29,28,27,13,26,25,12,9,10,8,24,23,7,5,18,30,21,20,3,1,19,2), ue.`sub_region` ASC, ue.`country` ASC, ue.`state` ASC, ue.`city` ASC
Last edit: 3 years 2 weeks ago by galanopd.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48541
  • Thanks: 8290
  • Karma: 1445
3 years 2 weeks ago #326900 by krileon
Replied by krileon on topic Sort List
You're just running an independent query is why it works fine because as a query there's nothing wrong with it, but as a subquery in an ORDER BY clause it won't work. The Advanced Sorting directly adds whatever you supply to the ORDER BY clause. Example as follows.

Advanced Sorting:
Code:
u.`name` DESC
Result:
Code:
ORDER BY u.`name` DESC
Userlist Query:
Code:
SELECT * FROM `jos_users` u INNER JOIN `jos_comprofiler` AS ue ON ue.`id` = u.`id` WHERE u.`block` = 0 AND ue.`approved` = 1 AND ue.`confirmed` = 1 AND ue.`banned` = 0 ORDER BY u.`name` DESC LIMIT 0, 30


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 or Create an account to join the conversation.

  • galanopd
  • galanopd
  • OFFLINE
  • Posts: 374
  • Thanks: 49
  • Karma: 8
3 years 2 weeks ago - 3 years 2 weeks ago #326941 by galanopd
Replied by galanopd on topic Sort List
After quite a lot of "pain" I need to ask, is it doable within the sorting tab to follow this specific order within the subquery or am I simply wasting my time?

I have tried almost everything following your examples but no luck so far.
Code:
ORDER BY FIELD(sub.`plan_id`, 14,35,34,33,32,31,17,16,15,11,29,28,27,13,26,25,12,9,10,8,24,23,7,5,18,30,21,20,3,1,19,2)

Thanks

EDIT: Ok I think I have ended up with something that seems to be working. I would appreciate it to have a look and tell me if I am on the right path.
Code:
( SELECT FIELD(sub.`plan_id`, 14,35,34,33,32,31,17,16,15,11,29,28,27,13,26,25,12,9,10,8,24,23,7,5,18,30,21,20,3,1,19,2) AS pid FROM `#__cbsubs_subscriptions` AS sub WHERE sub.`plan_id` IN (14,35,34,33,32,31,17,16,15,11,29,28,27,13,26,25,12,9,10,8,24,23,7,5,18,30,21,20,3,1,19,2) AND sub.`user_id` = u.`id` AND sub.`status` = 'A' ORDER BY pid, ue.`cb_region` ASC, ue.`cb_country` ASC, ue.`cb_state` ASC, ue.`cb_city` ASC LIMIT 1, 30)
Last edit: 3 years 2 weeks ago by galanopd.

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

  • krileon
  • krileon
  • ONLINE
  • Posts: 48541
  • Thanks: 8290
  • Karma: 1445
3 years 2 weeks ago - 3 years 2 weeks ago #326943 by krileon
Replied by krileon on topic Sort List
I don't think that's correct as you're again treating it like a standard query. You're adding a subquery to the ORDER BY clause so it's not the same as just running a regular query. I think something like the below might work purely based off your own code, but I did not test it.

Code:
( SELECT FIELD(sub.`plan_id`, 14,35,34,33,32,31,17,16,15,11,29,28,27,13,26,25,12,9,10,8,24,23,7,5,18,30,21,20,3,1,19,2) AS pid FROM `#__cbsubs_subscriptions` AS sub WHERE sub.`plan_id` IN (14,35,34,33,32,31,17,16,15,11,29,28,27,13,26,25,12,9,10,8,24,23,7,5,18,30,21,20,3,1,19,2) AND sub.`user_id` = u.`id` AND sub.`status` = 'A' ), ue.`cb_region` ASC, ue.`cb_country` ASC, ue.`cb_state` ASC, ue.`cb_city` ASC

Might not work if they've more than 1 subscription though so might need to add LIMIT 1 to the subscription query.

Code:
( SELECT FIELD(sub.`plan_id`, 14,35,34,33,32,31,17,16,15,11,29,28,27,13,26,25,12,9,10,8,24,23,7,5,18,30,21,20,3,1,19,2) AS pid FROM `#__cbsubs_subscriptions` AS sub WHERE sub.`plan_id` IN (14,35,34,33,32,31,17,16,15,11,29,28,27,13,26,25,12,9,10,8,24,23,7,5,18,30,21,20,3,1,19,2) AND sub.`user_id` = u.`id` AND sub.`status` = 'A' LIMIT 1), ue.`cb_region` ASC, ue.`cb_country` ASC, ue.`cb_state` ASC, ue.`cb_city` ASC

This is probably going to be pretty bad performance though. It'd actually be better to create a field in CB > Field Management to hold their plan index value. I recommend using an integer field. You can then hide it from profile edit using CB Conditional or CB Privacy. Next within your plans using the CBSubs Fields integration set whatever order index you want for each plan in those plans field settings. Now you'd just order your userlist by that field and not need a subquery at all, but you'll need to update the database for all existing subscribers. So for example you'd have the following within your plans.

Plan 14
Integrations > Fields
Field: cb_planindex
Operator: Set
Value: 1
Remove value on plan deactivation: Yes

Plan 35
Integrations > Fields
Field: cb_planindex
Operator: Set
Value: 2
Remove value on plan deactivation: Yes


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: 3 years 2 weeks ago by krileon.
The following user(s) said Thank You: galanopd

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

  • galanopd
  • galanopd
  • OFFLINE
  • Posts: 374
  • Thanks: 49
  • Karma: 8
3 years 2 weeks ago - 3 years 2 weeks ago #326944 by galanopd
Replied by galanopd on topic Sort List
No, neither mine nor yours work perfectly. They fail to sort correctly according to all ORDER BY commands.
So I will follow your advice and create a field in CB > Field Management.

I've waisted too much time already with this. Your suggestion seems to be far better.

Thank you Kyle
Last edit: 3 years 2 weeks ago by galanopd.
The following user(s) said Thank You: krileon

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

  • galanopd
  • galanopd
  • OFFLINE
  • Posts: 374
  • Thanks: 49
  • Karma: 8
3 years 2 weeks ago - 3 years 2 weeks ago #326949 by galanopd
Replied by galanopd on topic Sort List
I was thinking...
If a user subscribes to a plan, he will also be subscribed to its parent plan.
Now, since the planindex field is used for one plan, which of the two will it append?
Last edit: 3 years 2 weeks ago by galanopd.

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

Moderators: beatnantkrileon
Powered by Kunena Forum