oracle259 Posted October 13, 2006 Share Posted October 13, 2006 How can i order my mysql result by the length of the wordegsay i have the following words in my dbstringstringeststringerhow can i get the mysql to search through the db and produce results in the following orderstringeststringerstring Quote Link to comment https://forums.phpfreaks.com/topic/23872-solved-ordering-mysql-result/ Share on other sites More sharing options...
tleisher Posted October 13, 2006 Share Posted October 13, 2006 Use usort(), and create a function like this:function sort($a, $b){ if(strlen($a) > strlen($b)) { $a = 1; } else { $a = -1 }} Quote Link to comment https://forums.phpfreaks.com/topic/23872-solved-ordering-mysql-result/#findComment-108441 Share on other sites More sharing options...
oracle259 Posted October 13, 2006 Author Share Posted October 13, 2006 I tried that but can it be done in the mysql command itselflike SEARCH * FROM table ORDERBY *** Quote Link to comment https://forums.phpfreaks.com/topic/23872-solved-ordering-mysql-result/#findComment-108442 Share on other sites More sharing options...
simcoweb Posted October 13, 2006 Share Posted October 13, 2006 It would be ORDER BY then the column you want it sorted with... like 'id' or similar. Quote Link to comment https://forums.phpfreaks.com/topic/23872-solved-ordering-mysql-result/#findComment-108477 Share on other sites More sharing options...
tleisher Posted October 13, 2006 Share Posted October 13, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/23872-solved-ordering-mysql-result/#findComment-108484 Share on other sites More sharing options...
.josh Posted October 13, 2006 Share Posted October 13, 2006 select * from table order by length(columnname) Quote Link to comment https://forums.phpfreaks.com/topic/23872-solved-ordering-mysql-result/#findComment-108486 Share on other sites More sharing options...
oracle259 Posted October 13, 2006 Author Share Posted October 13, 2006 Thanks this one is solved Quote Link to comment https://forums.phpfreaks.com/topic/23872-solved-ordering-mysql-result/#findComment-108494 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.