It would probably be best to sort by the item id. You can get the id for the first item in the cart with this value:
<?php echo $eCart1->DisplayInfo("ID"); ?>
You would use the name of your cart in place of eCart1. You can also get the value directly from the bindings tab under the eCart object. You could loop over the items in the cart to get the id for each one using an eCart loop like this:
<?php
while (!$eCart1->EOF()) { //start the loop
?>
code to loop over here
<?php
$eCart1->MoveNext(); // go to the next item in the cart
}
$eCart1->MoveFirst(); //after looping over all of the items go back to the first one
?>