mlseim, thanks for the suggestion. I hadn't considered the possibility of doing some of the sorting through MySQL.
I'm going to leave this thread on here for a few days to see if anyone has any ideas to get my script working. I'd really like to figure out how to do this through PHP.
If nobody has an idea on whether/how it's possible, I'll try in the MySQL section of the forums.
Thanks again for the help everyone—I'm looking forward to hearing any suggestions for the script!