Oh, right
I know you got a solution now but I'm going to ramble on anyway
You could have 'name' and 'occurance' in the table, so Sausage in the name field an 7 in the occurance field. Or when you put it into the database, you could use php to format it so it's sausage0007 which would allow for 9999 occurances of 'sausage', and the 0's would keep them in the correct order.
Doing one of those would mean you won't need to do any phpness, could keep all the ordering in the mysql query
But it would also mean changing the way your database works, and seeings you already have a solution there's probably not much point...
But yeah, could be handy knowledge for future reference