It would help to see code, but if you are doing some kind of query and getting a result with multiple rows and then fetching each row one by one in a while loop, I don't understand how you can possibly do any sorting inside the loop because inside the loop, there's only a single row at a time.
If you want to sort your results by item name, then you just use the sql query to do that, such as:
$query = "SELECT * FROM items ORDER BY item_name ASC";
If your problem is that you need to sort by one field in the query and then another field as well, you can actually sort by two fields in the query like so:
$query = "SELECT * FROM items ORDER BY item_name ASC, username ASC";
It sounds from your post that you already know this, but if so, then what's the problem exactly? Again, specific examples of your code will help.
I'm not too clear on what the problem is but hopefully this is of some help. If not, give me some more details and we can go from there.