in reply to reordering lists

I think it's rather a matter of design. I would prefer to keep the code as simple as possible: do sorting at database level, and keep the (business) logic as simple as possible.

Assume that your tables are defined some what like this -
house_idkitchen_idbathroom_id
1101103
2102104

image_idimage_namedate_entered
101image01.jpg2004/01/02-11:30
102image02.jpg2004/01/02-13:30
103image03.jpg2004/01/03-12:30
104image04.jpg2004/01/05-13:30

Then I would introduce a hash table of SQL statements in the code, indexed by the alias of sorting order. The following code is not tested, just an idea on how this problem may be tackled.

my %SQL = ( order_by_date => 'select image_name from image where house_id in ( select kitchen_id, bathroom_id from house where house_id=? ) order by image_date', kitchen_first => 'select image_name from image where image_id = ( select kitchen_id, bathroom_id from house where house_id = ? )', bathroom_first => 'select image_name from image where image_id = ( select bathroom_id, kitchen_id from house where house_id = ? )', ); .... $sth = $dbh->prepare( $SQL{order_by_date} ); .... $sth = $dbh->prepare( $SQL{kitchen_first} ); ....