I am creating a class for Contact management and I am curious if anyone has any creative ideas to pass in options to make certain columns sortable via ORDER BY in MySQL.
There are 5 columns. ID, Firstname, Lasname, Phone Number, Email.
All of these will need to be sortable Ascending and Descending. The obvious answer would just be to pass in a string for instance “firstname DESC” — but seems a little to open and would like to make the class a little more restrictive.
Any ideas?
The type-safest method would be to use an object which can only hold certain values:
Gets you all the advantages of strict typing and enumerations. Can be a little bit of an overkill though to have to define, test and include a separate class for every function argument.
Otherwise, you’ll have to check inside the function: