The below code give me a foreach error. What appears to be the issue with my code?
$my_word = $_REQUEST['value'];
$bestMatch = array('word' => $my_word, 'match' => 2);
$result = mysql_query("SELECT keyword FROM keywords");
$storeArray = Array();
foreach ($result as $keyword) {
$lev = levenshtein ($keyword, $my_word, 1, 2, 1);
if (!isset($lowest) || $lev < $lowest) {
$bestMatch = array('word' => $keyword, 'match' => $lev);
$lowest = $lev;
}
}
if ($bestMatch['match'] > 0)
echo 'Did you mean: <strong>'.$bestMatch['word'].'</strong> l:'.$bestMatch['match'];
Replace this:
With this:
mysql_query() just returns a resource, you need the actual results, so you need to use mysql_fetch_array() as well.
Also, the mysql_* functions are being deprecated so you should look into PDO or mysqli.