Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


php mysql creating a list and sorted

Posted on 2011-05-06
Medium Priority
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
  • 3
LVL 111

Expert Comment

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

Author Comment

ID: 35705495
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

ID: 35705498
Sorry order the tables by section order

and order the contents of the tables by category ordeR?

Accepted Solution

rubene earned 1500 total points
ID: 35705625
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

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

572 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