News:

CPG Release 1.6.29
During HTML5 upload, keep pseudo blank code 200 messages from triggering error condition
added Russian language
correct failure to use theme menu icons in album manager
minor vulnerabilities mitigation

Main Menu

technical problem sorting a list

Started by Frederick, December 12, 2005, 01:13:29 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Frederick

Hi all,

some code I've written http://coppermine-gallery.com/forum/index.php?topic=24466.msg114097#msg114097 refuses
to be sorted:
here you see the list it produces: http://cpcomp.mybesthost.com/boom.php

I want to sort that list alphabetically by genus (first column) and then by species (second column).
I've tried variations on multi_sort(), asort() and proper sort functions, but the problem seems to be that I can't find
how to sort by index.

My multi-dim array is declared like this:


$sorted = array(array(array(),array(),array()));


and filled-in like this:



foreach($rowset as $key => $row){

$genus = $row['user1'];
$species = $row['user2'];
$title = $row['title'];
$pict_id = $row['pid'];
$owner = $row['owner_name'];

$temp = count($sorted[$genus][$species]);

$sorted[$genus][$species][$temp][0] =$title;
$sorted[$genus][$species][$temp][1] =$pict_id;
$sorted[$genus][$species][$temp][2] =$owner;

}


which results in this kind of array:



array(20) { ["Cymbidium"]=> array(2) { ["goeringii"]=> array(4) { [0]=> array(3) { [0]=> string(19) "Cymbidium goeringii"
[1]=> string(2) "79"
[2]=> string(14) "KyushuCalanthe"
}
[1]=> array(3) { [0]=> string(28) "Cymbidium goeringii seed pod"
[1]=> string(2) "77"
[2]=> string(14) "KyushuCalanthe"
}
[2]=> array(3) { [0]=> string(19) "Cymbidium goeringii"
[1]=> string(2) "75"
[2]=> string(14) "KyushuCalanthe"
}
[3]=> array(3) { [0]=> string(19) "Cymbidium goeringii"
[1]=> string(2) "74"
[2]=> string(14) "KyushuCalanthe"
}
}
["kanran"]=> array(1) { [0]=> array(3) { [0]=> string(16) "Cymbidium kanran"
[1]=> string(2) "69"
[2]=> string(14) "KyushuCalanthe"
}
}
}
["Calanthe"]=> array(4) { ["discolor"]=> array(1) { [0]=> array(3) { [0]=> string(17) "Calanthe discolor"
[1]=> string(2) "78"
[2]=> string(14) "KyushuCalanthe"
}
}
["sieboldii"]=> array(1) { [0]=> array(3) { [0]=> string(18) "Calanthe sieboldii"
[1]=> string(2) "76"
[2]=> string(14) "KyushuCalanthe"
}
}
[""]=> array(8) { [0]=> array(3) { [0]=> string(23) "Calanthe complex hybrid"
[1]=> string(2) "71"
[2]=> string(14) "KyushuCalanthe"
}
[1]=> array(3) { [0]=> string(33) "Calanthe "sedenii pink""
[1]=> string(2) "35"
[2]=> string(9) "Frederick"
}
[2]=> array(3) { [0]=> string(28) "Calanthe "Brian K""
[1]=> string(2) "34"
[2]=> string(9) "Frederick"
}
[3]=> array(3) { [0]=> string(14) "Calanthe rosea"
[1]=> string(2) "31"
[2]=> string(9) "Frederick"
}
[4]=> array(3) { [0]=> string(24) "Unknown Calanthe variety"
[1]=> string(2) "30"
[2]=> string(9) "Frederick"
}
[5]=> array(3) { [0]=> string(24) "Unknown Calanthe variety"
[1]=> string(2) "29"
[2]=> string(9) "Frederick"
}
[6]=> array(3) { [0]=> string(35) "Calanthe "William Murray""
[1]=> string(2) "25"
[2]=> string(9) "Frederick"
}
[7]=> array(3) { [0]=> string(34) "Calanthe "sedenii white""
[1]=> string(2) "24"
[2]=> string(9) "Frederick"
}
}
["reflexa"]=> array(1) { [0]=> array(3) { [0]=> string(16) "Calanthe reflexa"
[1]=> string(2) "70"
[2]=> string(14) "KyushuCalanthe"
}
}
}
...etc.
[code]


any help would be greatly appreciated.

Regards,
Fred
[/code]

Abbas Ali

Why don't you sort the results in the query itself.

Replace (in your other post)


$result = db_query("SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' $ALBUM_SET ORDER BY pid DESC $limit");


with


$result = db_query("SELECT $select_columns FROM {$CONFIG['TABLE_PICTURES']} WHERE approved = 'YES' $ALBUM_SET ORDER BY user1,user2 $limit");


By doing this the results will come sorted

HTH
Abbas
Chief Geek at Ranium Systems

Frederick

<sound of hand slapping forehead>

Thank you Abbas, problem solved.

regards,
Frederick