Non so se ho capito bene, ma ti basterebbe una

ORDER BY

nella SELECT da cui arrivano i tuoi dati ...