Order by

ORDER BY is just about sorting the rows that come back from a SELECT.

Without it, MySQL gives you rows in whatever order it decides. With ORDER BY, you tell it which column should control the order of the result. So if you order by name, the rows come back sorted by the name column instead of in random-looking database order.

By default, ORDER BY sorts in ascending order. That usually means A to Z for text and smaller to bigger for numbers. If you want the reverse, you add DESC. You can also be explicit with ASC, but if you leave it out, ascending is the default.

So the flow is still the same as the last two lessons: write a SELECT, run it, get the result set, loop through it. The only new thing is that the result set is now sorted before PHP starts reading the rows. :contentReference[oaicite:0]{index=0}