3.5. Sorting

phpMyEdit offers powerful default and/or additional sorting capabilities via $opts['sort_field'] option. You can define the column name or column field number that you'd prefer to sort on when the script is first loaded. To get descending sort order, prefix the column name or field number with dash (-) sign. Look at the following examples:

Example 3-14. Sort field option

$opts['sort_field'] = 'company'; // sorting according company field 
$opts['sort_field'] = 3;         // sorting according 4th field 
$opts['sort_field'] = '-id';     // descending sorting according id field

Now, let's assume you want to sort your table according to the 'company' column, but in addition also according to the 'department' column. So the default sort order should be by company first, then department. For this purpose, you can set an array with column names and/or field numbers to $opts['sort_field'] variable.

Example 3-15. Multiple sort fields

$opts['sort_field'] = array('company', 'department');

Also note that phpMyEdit's sorting feature is cumulative. This means, that if default sort fields are specified and the user selects (clicks) to sort by another column in table listing screen, the resulting screen will be sorted by user selected column first and then by specified default sort fields. Next click on another sort column will again force to sort table by selected column first. Previously selected fields or default ones will follow up in sorting sequence.

This feature enables selecting more than one sort field on the fly. To clear sort fields sequence and to initialize the default one, click on Clear link in left upper corner. This link could be enabled by setting $opts['display']['sort'] to true. See Special page elements subsection for more information. We also recommend you to enable this option to see how this described sorting feature works.

Bootstrap phpMyEdit PHP Form Generator