Jump to content

Archived

This topic is now archived and is closed to further replies.

oracle259

[ Solved ] ordering mysql result

Recommended Posts

How can i order my mysql result by the length of the word
eg

say i have the following words in my db

string
stringest
stringer

how can i get the mysql to search through the db and produce results in the following order

stringest
stringer
string

Share this post


Link to post
Share on other sites
Use usort(), and create a function like this:

function sort($a, $b)
{
    if(strlen($a) > strlen($b))
    {
          $a = 1;
    }
    else
    {
          $a = -1
    }
}

Share this post


Link to post
Share on other sites
I tried that but can it be done in the mysql command itself

like SEARCH * FROM table ORDERBY ***

Share this post


Link to post
Share on other sites
It would be ORDER BY then the column you want it sorted with... like 'id' or similar.

Share this post


Link to post
Share on other sites
ORDER BY needs a column to order from, you may be able to do ORDER BY `name` but Im not sure if it would work, give it a shot and find out.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.