mercredi 6 juillet 2016

How to search all PHP array elements in MySQL column [duplicate]

This question already has an answer here:

Updated: My issue has been resolved and works very well.

Note: All input sanitization and escaping is completed in my code but not shown here.

I have two PHP arrays: $search_exploded (user inputted search terms) and $metaphoneArr (metaphones of keywords in MySQL).

I'm cycling through $search_exploded and $metaphoneArr, and if the Levenshtein is less than 2, then I'm adding the metaphone element to a third array called $levenResultsArr.

In MySQL, I'm joining two tables, and if there's a result in my third array ($levenResultsArr) that matches a row in my metaphone_col, then I want the results printed. Somehow, though, I am not referencing the third array correctly in the MySQL statement.

Any advice? Here is part of my PHP code.

$levenResultsArr = array();
foreach($search_exploded as $search_each => $searchWord)
{
$search_each2=metaphone($searchWord);
echo $search_each2."<br>";

   foreach($metaphoneArr as $metaword => $val)
   {
    $lev = levenshtein($search_each2, $val);
    if ($lev < 2)
      {
        array_push($levenResultsArr, $search_each2);

      }
    }

It's only searching using the last word in the array instead of all words in the array.

Aucun commentaire:

Enregistrer un commentaire