Jump to content

Ordering data from SQL table


Sharkadder
 Share

Recommended Posts

Hi there,

 

I have an SQL table which has a field within it that holds data within a row. The field holds data for outcomes which can be listed as follows:

Outcome 1

1.1

1.2

Outcome 2

2.1

2.2

1.3

Outcome 4

4.1

4.2

Outcome 3

3.1

1.4

 

etc.

 

Basically, they are not in order as people have been typing them into the database table in a random order. Is there a way i can get it so that it shows everything to do with outcome 1 under outcome 1 etc. once i pull the rows from the database?

 

e.g.

Outcome 1

1.1

1.2

1.3

1.4

Outcome 2

2.1

2.2 etc.

 

I have tried assending and decsending orders but they obviously show the numeric data first. Currently i am having to use several foreach loops in PHP to sort out the ordering and would like a more efficient way of doing this. Was not sure if i could do a command in MySQL direct. I am using MySQL 5.0

 

Many thanks

Edited by Sharkadder
Link to comment
Share on other sites

You should add a purely numeric field in the database table by which to order these which gets determined as you insert the data into the database. What does your table structure look like?

Link to comment
Share on other sites

Hi there,

It is ok i sorted this now, happens that i had a parent outcome id field in my table and so each sub-outcome had a parent id which was linked to the main outcome ID. All i did was get the main outcome ID's from the database in ascending order, and then search for each sub-criteria who had that main outcome ID as their parent...then i was able to capture the information in the order i needed.

 

Many thanks,

 

Mark

Edited by Sharkadder
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...