One further question though - my results come out in a seemingly random order and cannot be sorted in any way. I believe this is due to the nature of hashes, and you can't guarantee in which order they are returned.
Is there any simple way of modifying this so that I can have some control over how the results are sorted when displayed on screen? Something as simple as sorting by $i_id would be good!