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

		}

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.