0

I have a working bit of code that gets a bunch of material from a MySQL table, searches for a pattern, and then orders and prints the results. So far, so good.

But now I need to do something similar across two fields in the result. So the code below searches for the pattern in the "essay" column, but I need it to find matches in the "essay" column OR the "definitions" column. If either one is a hit, I want the code to add the row to the $matches and proceed from there. (In other words, I want it to treat "essay" and "definitions" together, rather than just "essay," as the code below does.)

I tried a few ways that I thought might signify "or" in this way, but nothing worked. Any help would be much appreciated.

// create empty array

$query = "SELECT shortword,word,essay,definitions FROM lexicon;";
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$num_results = mysql_num_rows($result);

$results = array();
for ($i = 0; $i < $num_results; $i++) {
    $row = mysql_fetch_array($result);
    if (preg_match_all("/(\<i\>U\<\/i\>|U) $episodenav\.[0-9]{1,4}\D/", $row["essay"], $matches)) {
        foreach ($matches[0] as $match) {
            $match = ltrim(strip_tags($match), "U ");
            // array pseudo key is the float value of $match
            // add '_key' member for usort()
            $row['_key'] = floatval($match);
            $results[] = $row;
        }
    }
}

1 Answer 1

0

Did you try like this ?

$newtext=   $row["essay"]." ".$row["essay"]

if (preg_match_all("/(\<i\>U\<\/i\>|U) $episodenav\.[0-9]{1,4}\D/", $newText, $matches)) {
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.