PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
How would I do a mysql_query that ordered by the length of text in a particular field?
I have a submenu script that displays all the pages in a directory of my website, however, for stylistic reasons, I want it to be ordered by the length of the title for each page on the submenu.
As Feyd said, LENGTH() will work just fine - if you're using multi-byte characters (i.e. a foreign language character set) then use CHAR_LENGTH() instead, as LENGTH gives you an incorrect reading in this instance.
Welcome to non-proportional fonts. Try using PRE tags if you absolutely must have fixed-width characters (or set the font to be something like Courier or Terminal but realise you'll exclude Mac users, etc).
I have a sorta-solution. In the db, I put ? after the titles to "jack" up the character length. Then, after Ordering By the length of characters, I strip out the ?.
It doesn't always work, but it does make it look a LOT better, and by golly it's better than nothing!