Support

Home Forums Event Espresso Premium Alphabetizing category results

Alphabetizing category results

Posted: December 31, 2012 at 9:58 pm

Viewing 11 reply threads


jeff nickel

    December 31, 2012 at 9:58 pm

    I’ve created categories that output to a table. They are Alphanumeric, but always start with a number. Currently, their output seems random. I’d like to order them from low to high (8U 9U 10U, etc.) Here is an example. It’s the last column of the table I’m trying to re-order http://utrip.pickorange.com/event-list/

    I saw this similar post, but couldn’t figure it out as the code has changed around a bit. http://staging.eventespresso.com/forums/2010/09/order-listing-of-categories/

    I’m aware that manual sorting is on the list for future enhancements, but for now, is there a way I can accomplish this with some kind of sort()?

    Thanks!
    Jeff


    Chris Reynolds

    • Support Staff

    January 1, 2013 at 2:37 pm

    The order is most likely by category ID, which should correspond with the order in which the categories were created. You could go and rename all your categories so they are sequential that way. The other option would be modifying the SQL query. Depending on where you are trying to make this happen would determine what template files would need to be modified.


    jeff nickel

      January 2, 2013 at 9:21 pm

      I don’t think it’s SQL ID. Here is the result of my Category table.

      Category Table

      Yet I’m still getting results like this:

      enter image description here

      I’m using the custom file template espresso_table.php to get the table. Is there any kind of JS or PHP sort I can apply to just that cell?


      jeff nickel

        January 5, 2013 at 10:05 am

        Any other suggestions?


        jeff nickel

          January 5, 2013 at 11:22 pm

          I’ve found that I can control the order by editing the events_category_rel values in phpMyAdmin. I have over 250 rows and would rather not edit them all every time I load an event. Is there some kind of code that will keep this table sorted properly going forward?

          Is there any kind of sql query I can run on the events already loaded to fix this?

          I’m really stuck here and need to get this fixed.

          Thanks!


          Dean

          • Support Staff

          January 7, 2013 at 6:28 am

          Hi,

          You could try the PHP function sort

          This is an example from the link above. Basically you run the array through the sort function. You might not even need the foreach

          <?php
          
          $fruits = array("lemon", "orange", "banana", "apple");
          sort($fruits);
          foreach ($fruits as $key => $val) {
              echo "fruits[" . $key . "] = " . $val . "\n";
          }
          
          ?>
          


          jeff nickel

            January 7, 2013 at 9:34 pm

            This option shows a defined array. Mine is not defined as it’s determined by which categories are clicked on the event?

            I don’t understand why this is happening if the IDs of all of the categories are in order in the MySQL database?

            There must be some code in EE somewhere along the way that can tell the database to spit out the category results in ASC order. I don’t care if I have to modify core files. This is a necessity.

            Here is my code if it helps:

                start_date, $format = 'm/d/y') ?&gt;
            
                id.'" show_address="false" show_description="false" show_map_image="false" title_wrapper="p" show_additional_details="false"]'); ?&gt;
                id.']') ?&gt;
            

            Ideally, I’d love to modify Category_Name as a custom shortcode and add the code here. Possible?


            jeff nickel

              January 7, 2013 at 9:37 pm

              ummm… that’s not what I pasted as my code.

                  start_date, $format = 'm/d/y') ?&gt;
              
                  id.'" show_address="false" show_description="false" show_map_image="false" title_wrapper="p" show_additional_details="false"]'); ?&gt;
                  id.']') ?&gt;
              


              jeff nickel

                January 7, 2013 at 9:39 pm

                enter image description hereWell, I guess code pasting doesn’t work.


                Dean

                • Support Staff

                January 8, 2013 at 12:18 am

                Hi Jeff,

                This will do what you want, but with one criteria – single digit numbers require a zero in front – eg 8U becomes 08U, otherwise in order, 10U comes before 8U (1 before 8).

                <?php 
                $my_cats = do_shortcode('[CATEGORY_NAME event_id="' . $event->id . '"]');
                $my_cats = explode(" ", $my_cats); //turns the string into an array
                sort($my_cats);
                foreach ($my_cats as $key => $val) {
                echo $val . " ";
                }
                ?>
                


                jeff nickel

                  January 15, 2013 at 5:20 pm

                  Found out that PHP has built in Natural Support which solved the 0 in front issue.

                  Changed your code from sort($my_cats); to natsort($my_cats);

                  Problem solved! No need for 0’s and it’s all ordered correctly. Thank you so much! This has eluded me for weeks now!


                  Dean

                  • Support Staff

                  January 15, 2013 at 11:24 pm

                  Hi Jeff,

                  No problem, and thanks for posting the natsort answer, very useful to know!

                  Viewing 11 reply threads

                  The support post ‘Alphabetizing category results’ is closed to new replies.

                  Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

                  Event Espresso - Staging Server