I am using the following query:
$query = "SELECT * FROM `$table[$a]` ORDER BY FIELD(typeof,'pdf','swf','img','web')";
to select and customly order my mysql query, it works great except there are multiple files within each typeof and I now want to order them alphabetically yet retaining their typeof order. Make sense?
Use the ORDER BY clause to sort the result set by one or more columns. Use the ASC option to sort the result set in ascending order and the DESC option to sort the result set in descending order.
If you want to select records from a table but would like to see them sorted according to two columns, you can do so with ORDER BY . This clause comes at the end of your SQL query.
By default SQL ORDER BY sort, the column in ascending order but when the descending order is needed ORDER BY DESC can be used. In case when we need a custom sort then we need to use a CASE statement where we have to mention the priorities to get the column sorted.
When combining the Group By and Order By clauses, it is important to bear in mind that, in terms of placement within a SELECT statement: The GROUP BY clause is placed after the WHERE clause. The GROUP BY clause is placed before the ORDER BY clause.
SELECT * FROM `$table[$a]`
ORDER BY
FIELD(typeof,'pdf','swf','img','web'), --first order by type
filename --then by filename
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With