Mysqli按自定义顺序查询订单

Hi im writing a php where i call all the States in a list, im doing like this.

$result = mysqli_query($con,"SELECT * FROM ".TABLE_PREFIX."states WHERE ccode='MX'");

The problem is i Need to set a custom order, not by ABC or Numeric, its basically a Custom order, (based on id i think ) , So i now i can user "Order By", but i dont now wich way you set a custom order like "Order by ID (3,5,28,34,13,etc..)

$result = mysqli_query($con,"SELECT * FROM ".TABLE_PREFIX."states WHERE ccode='MX' Order by ID '3,5,28,34,13' ");

How can i do this...Thanks in advance..

The function you are looking for is find_in_set():

SELECT *
FROM ".TABLE_PREFIX."states
WHERE ccode='MX'
Order by find_in_set(ID, '3,5,28,34,13')

This returns the index in the "set", which is what you want for ordering.