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! Link to comment https://forums.phpfreaks.com/topic/39316-simple-but-cant-get-my-head-around-it/ 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 Link to comment https://forums.phpfreaks.com/topic/39316-simple-but-cant-get-my-head-around-it/#findComment-189539 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++; } Link to comment https://forums.phpfreaks.com/topic/39316-simple-but-cant-get-my-head-around-it/#findComment-189547 Share on other sites More sharing options...
glenelkins Posted February 20, 2007 Author Share Posted February 20, 2007 - Link to comment https://forums.phpfreaks.com/topic/39316-simple-but-cant-get-my-head-around-it/#findComment-189552 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 Link to comment https://forums.phpfreaks.com/topic/39316-simple-but-cant-get-my-head-around-it/#findComment-189555 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 Link to comment https://forums.phpfreaks.com/topic/39316-simple-but-cant-get-my-head-around-it/#findComment-189558 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 Link to comment https://forums.phpfreaks.com/topic/39316-simple-but-cant-get-my-head-around-it/#findComment-189561 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.