Fasten PHP foreach and mysql query
I want to fasten this php code. It is taking a very very very long time to execute when the no. of foreach queries increases... Also there are more than 1 million records in my table. It also makes it slow...

Is there any way to make it fast???

Here's the code...


    function checkspell($string, $translate) {
    		$counter = 0;
            $arr = explode(" ",convert($translate, "Arial Unicode MS", $string));
            foreach($arr as $str) {
                $text = substr($str, 0, 3);
                $exists = mysql_query("SELECT COUNT(word) FROM unicode WHERE word = '$str'") or die (mysql_error());
                $sugges = 0;
                if (mysql_result($exists, 0) == 0) {
                $words = mysql_query("SELECT * FROM unicode WHERE word LIKE '$text%' ORDER BY word") or die (mysql_error());
                $counter++;
                    echo "<span class=\"error\" sug=\"$counter\">$str </span><div class=\"suggestions $counter\">";
                    while ($row = mysql_fetch_assoc($words)) {
                        $word = $row['word'];
                        similar_text($word, $str, $percent);
                        if ($percent > 84) {
                            echo "<span class=\"sugg\" sugges=\"$word \" idt=\"$counter\">$word </span>";
                            $sugges++;
                        }
                    }
                    if ($sugges == 0) {
                    echo "<span class=\"nosug\">No Suggestions Found...</span>";
                    }
                    echo "<hr size=\"1\" color=\"#ccc\"><span class=\"as\">Synonyms</span><span class=\"as\">Antonyms</span></div>";
                } else {
                echo "<span class=\"whps\">$str </span>";
                }
            }
    }

Thanks in advance...

Fasten PHP foreach and mysql query
===

I want to fasten this php code. It is taking a very very very long time to execute when the no. of foreach queries increases... Also there are more than 1 million records in my table. It also makes it slow...

Is there any way to make it fast???

Here's the code...


    function checkspell($string, $translate) {
    		$counter = 0;
            $arr = explode(" ",convert($translate, "Arial Unicode MS", $string));
            foreach($arr as $str) {
                $text = substr($str, 0, 3);
                $exists = mysql_query("SELECT COUNT(word) FROM unicode WHERE word = '$str'") or die (mysql_error());
                $sugges = 0;
                if (mysql_result($exists, 0) == 0) {
                $words = mysql_query("SELECT * FROM unicode WHERE word LIKE '$text%' ORDER BY word") or die (mysql_error());
                $counter++;
                    echo "<span class=\"error\" sug=\"$counter\">$str </span><div class=\"suggestions $counter\">";
                    while ($row = mysql_fetch_assoc($words)) {
                        $word = $row['word'];
                        similar_text($word, $str, $percent);
                        if ($percent > 84) {
                            echo "<span class=\"sugg\" sugges=\"$word \" idt=\"$counter\">$word </span>";
                            $sugges++;
                        }
                    }
                    if ($sugges == 0) {
                    echo "<span class=\"nosug\">No Suggestions Found...</span>";
                    }
                    echo "<hr size=\"1\" color=\"#ccc\"><span class=\"as\">Synonyms</span><span class=\"as\">Antonyms</span></div>";
                } else {
                echo "<span class=\"whps\">$str </span>";
                }
            }
    }

Thanks in advance...
