glenelkins Posted February 20, 2007 Share Posted February 20, 2007 Hi I have an array like this: $words_array[$position]['word'] ====> full of words $words_array[$position]['percent'] =====> percentages I want to sort all the words by the "percent" section putting the largest first. I know how to use a bubble sort but cant get my head around the code...bad day! Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted February 20, 2007 Share Posted February 20, 2007 I believe you should reorganize them to: $array[$percentage] = $words; and then use sort($array); I think that would do it. Ted Quote Link to comment Share on other sites More sharing options...
glenelkins Posted February 20, 2007 Author Share Posted February 20, 2007 I dont think that would work, as there are multiple words for each percentage in some cases. They are added in a loop from database: while ( $words = mysql_fetch_array ( $result ) ) { similar_text ( $search_word, $words['word'], $match_percent ); $words_array[$counter]['word'] = $words['word']; $words_array[$counter]['percent'] = $match_percent; echo "<font color='red'>" . $words_array[$counter]['word'] . " => " . $words_array[$counter]['percent'] . "%</font><br>"; $counter++; } Quote Link to comment Share on other sites More sharing options...
glenelkins Posted February 20, 2007 Author Share Posted February 20, 2007 - Quote Link to comment Share on other sites More sharing options...
monk.e.boy Posted February 20, 2007 Share Posted February 20, 2007 why not let the DB sort them for you? SELECT words, percent FROM table ORDER BY percent DESC monk.e.boy Quote Link to comment Share on other sites More sharing options...
monk.e.boy Posted February 20, 2007 Share Posted February 20, 2007 why not let the DB sort them for you? SELECT words, percent FROM table ORDER BY percent DESC monk.e.boy Hm, doing this: SELECT words, percent FROM table ORDER BY percent DESC, words would give you the words in percentage order, then all those on 50% in alphabetical order. monk.e.boy Quote Link to comment Share on other sites More sharing options...
glenelkins Posted February 20, 2007 Author Share Posted February 20, 2007 This cannot be done. The program is a spell cheker. It takes an inputted word then first checks its metaphone value with all the words in the database. Then it finds the percentage of accuracy with all the words found. What i need is all the found words listed from 1-10 by the highest percentage first. Therfore removing obsolete word suggestions Quote Link to comment 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.