php mysql creating a list and sorted

Posted on 2011-05-06
Last Modified: 2012-06-27
Hi Experts,

This is going to take some explaining...

I have a mysql table that simplistically looks like this:

                 Section      Category     Section_order    Category_Order
entry 1       A                 A                      1
entry 2       B                 B                        2              
entry 3      B                  X                                                     1
entry 4       A                X                                                      1
entry 5       B                Y                                                     2
entry 6       A                 Y                                                   2

I want to end up with tables... firstly sorted into sections in section_order... Then within those sorted in category order... like so:

Table 1
Entry 1
Entry 4
Entry 6

Table 2
Entry 2
Entry 3
Entry 5

Could you help me deliver a clean php code... the only way I can work it involves too many lines of php...

Many Thanks in advance
Question by:maccaj51
    LVL 107

    Expert Comment

    by:Ray Paseur
    Looks like your query would say something like ORDER BY Section, right?

    Author Comment

    Yeah but how would you then split it into tables and order them bu category order?

    Am i going to have to just do multiple queries?

    Author Comment

    Sorry order the tables by section order

    and order the contents of the tables by category ordeR?
    LVL 6

    Accepted Solution

    You can specify more than one order by column:

    i.e. SELECT * FROM entries ORDER BY Section_Order,Category_Order

    I don't know if you actually want the Table 1 and Table 2 headers included in your output, but if you do you'd need to write a mysql function or procedure.

    Author Closing Comment

    Didnt know you could do that... Ive worked a way round it!

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    Suggested Solutions

    Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
    Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now