I am trying to check if the words in a large sentence (10k or more words) are present in a dictionary, however executing my query this many times makes my page slow. How can I move the query outside the loop to speed the page up?
foreach ($word as $key => $value) {
$checkWord = checkDict($value);
if($checkWord==true){
return $value;
} else {
$word[$key] = Del_Inflection_Suffixes($value); //skip this function
if(checkWord($value)){
return $value;
}
$word[$key] = Del_Derivation_Suffixes($value); //skip this function
if(checkWord($value)){
return $value;
}
$word[$key] = Del_Derivation_Prefix($value); //skip this function
if(checkWord($value)){
return $value;
}
}
}
function checkDict($rootWord){ //check if the word already exist in the database
$sql = mysql_query("SELECT * from dictionary where rootword ='$rootWord' LIMIT 1");
$result = mysql_num_rows($sql);
if($result==1){
return true;
}else{
return false;
}
}