So here is the working code.
Here are the sorting variables (it gets the custom sort options that a player has in their settings).
$sort1 = 'breed';
$sort2 = 'name';
SELECT CAGE_TABLE.rabbit, CAGE_TABLE.pig, CAGE_TABLE.id,
PIG_TABLE.breed, PIG_TABLE.name,
RABBIT_TABLE.breed...