Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Manual sorting of search results

Enthusiast ,
Jun 21, 2012 Jun 21, 2012

Is there a way to sort results manually without having to build stupidly complex arrays?

I need to sort initially in a very specific way like so:

Beer

Orange Juice

(then by A-Z)

Apple Juice

Brandy

Carrott Juice

Blah blah blah through to Z

Is it possible to do this even if I have to add the products in order manually?

I'm using PHP and MySQL.

Thank you.

TOPICS
Server side applications
688
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 21, 2012 Jun 21, 2012

OK, so just to let you know that I am getting something, but it's by no means right, but messing with the code does seem to alter the sort order:

ORDER BY DrinkType = 'Beer', DrinkType = 'Orange Juice', DrinkType = 'Apple Juice', DrinkType = 'Brandy', DrinkType = 'Carrot Juice', etc...

However, by presenting it in this manner, the results print backwards like so:

etc

Carrot Juice

Brandy

Apple Juice

Orange Juice

Beer

This is all very well, and I could change the order of the ORDER BY to be backwards so that it prints properly, but this isn't flexible and doesn't allow for new entries. Any new drink type NOT included prints before the specified sort order.

Does anybody have any thoughts on this?

Thanks.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 21, 2012 Jun 21, 2012
LATEST

How about creating a new column called 'sortfield'.  Assign 'aaa' to Beer and 'aab' to Orange Juice. For the rest of the items populate it with the same value as DrinkType. You could create a trigger to do that for you. Then just sort on the sortfield.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 21, 2012 Jun 21, 2012

I came across this extension of Tom Muck

http://www.tom-muck.com/extensions/help/SortRepeatRegion/

I never used it myself.

I used other extensions of Tom Muck an they were OK.

Best Regards,

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines