如果我有一个按 id/parent_id 排序的邻接列表,是否有一种简单的方法可以通过第三个文本字段(比如“名称”)按字母顺序对所有父母的孩子进行排序?
我使用了此处提供的信息:http: //explainextended.com/2009/03/17/hierarchical-queries-in-mysql/让 MySQL 返回排序的邻接列表。理想情况下,这将允许我按第三列对子项进行排序,但测试数据集在该示例中根本不包含额外的列。
我的数据在查询后看起来像这样,但它需要按字母顺序按后代排序。
$myArr[] = array(1,0,"instruments");
$myArr[] = array(2,1,"electric");
$myArr[] = array(3,1,"acoustic");
$myArr[] = array(4,2,"guitar");
$myArr[] = array(5,2,"banjo");
$myArr[] = array(6,3,"guitar");
$myArr[] = array(5,3,"banjo");
或者:
array (
0 =>
array (
0 => 1,
1 => 0,
2 => 'instruments',
),
1 =>
array (
0 => 2,
1 => 1,
2 => 'electric',
),
2 =>
array (
0 => 3,
1 => 1,
2 => 'acoustic',
),
3 =>
array (
0 => 4,
1 => 2,
2 => 'guitar',
),
4 =>
array (
0 => 5,
1 => 2,
2 => 'banjo',
),
5 =>
array (
0 => 6,
1 => 3,
2 => 'guitar',
),
6 =>
array (
0 => 5,
1 => 3,
2 => 'banjo',
),
)
我需要这样排序:
instruments
acoustic
banjo
guitar
electric
banjo
guitar
谢谢!