Jump to content

Simple but cant get my head around it


glenelkins

Recommended Posts

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

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++;

		}

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

 

 

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

Archived

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

×
×
  • Create New...

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.