I have a mysql query that works: This worked and showed the company alphabetically. Now however I have encrypted the database so now it is sorted by the encryption first letter rather than the decrypted text later. How can I add a function to the query or sort the $productR array using my decrypt($string) function? I tried' order by decrypt(user_company)' but it threw an error. Thanks