mysql sorting columns in php examaple


In PHP we can sort database results based on a column field using MySQL order by clause. Previously, we have seen about how to change the MySQL row order using jQuery.

Now, we are going to see an example to sort UI results by clicking on the column name in the header. We have a posts table containing sortable post_title, description, and post_at columns.

Creating Order by Query

By default, the posts table is sorted by the date column post_at in descending order. If any order by column is specified in query string then it will override the default values. This PHP script is declaring orderby column name for select query.

Sortable Header Links

The table header titles are links to send the order by and order values via the query string. This script is for computing next order value based on the current order.


Leave A Reply

Your email address will not be published.