I am using MYSQL and php version 5.4.16.My table structure is as given below.
I want to sort the temp_id cat_id and colors based on the cat_id as given in the second table.
The com_id same values should not come at once.

My Table is something like this:

col1 col2 col3
1   1   Black
2   1   Brown
3   1   green
4   2   red
5   2   yellow
6   2   white
7   3   blue
8   3   grey
9   3   orange
10  4   purple
11  4   yellow
12  4   white
13  5   blue
14  5   grey
15  5   orange

second table(I want my table something like as mentioned below

col1 col2 col3
1   1   Black
4   2   red
7   3   blue
10  4   purple
13  5   blue
2   1   Brown
5   2   yellow
8   3   grey
11  4   yellow
14  5   grey
3   1   green
6   2   white
9   3   orange
12  4   white
15  5   orange
Member Avatar

diafol

What are the names of the columns in the tables?? Your post doesn't make much sense.

Yep, I'm as confused as you are. That post made literally no sense. I've read and re-read that example several times.