Advanced search  

News:

cpg1.5.48 Security release - upgrade mandatory!
The Coppermine development team is releasing a security update for Coppermine in order to counter a recently discovered vulnerability. It is important that all users who run version cpg1.5.46 or older update to this latest version as soon as possible.
[more]

Pages: [1]   Go Down

Author Topic: technical problem sorting a list  (Read 4373 times)

0 Members and 1 Guest are viewing this topic.

Frederick

  • Coppermine newbie
  • Offline Offline
  • Posts: 16
technical problem sorting a list
« on: December 12, 2005, 01:13:29 pm »

Hi all,

some code I've written http://forum.coppermine-gallery.net/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:

Code: [Select]
$sorted = array(array(array(),array(),array()));

and filled-in like this:

Code: [Select]

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:

Code: [Select]

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]
« Last Edit: December 13, 2005, 09:49:40 am by GauGau »
Logged

Abbas Ali

  • Administrator
  • Coppermine addict
  • *****
  • Country: in
  • Offline Offline
  • Gender: Male
  • Posts: 2165
  • Spread the PHP Web
    • Ranium Systems
Re: technical problem sorting a list
« Reply #1 on: December 12, 2005, 01:35:00 pm »

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

Replace (in your other post)

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

with

Code: [Select]
$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
Logged
Chief Geek at Ranium Systems

Frederick

  • Coppermine newbie
  • Offline Offline
  • Posts: 16
Re: technical problem sorting a list
« Reply #2 on: December 13, 2005, 09:40:38 am »

<sound of hand slapping forehead>

Thank you Abbas, problem solved.

regards,
Frederick
Logged
Pages: [1]   Go Up
 

Page created in 0.019 seconds with 19 queries.