I have 2 related mysql tables. In one table brands, and in the second model. At the entrance we get the text in which you need to find a match by model and send to the list. The search itself works, there are no questions. The question is different. There are cases when the model is indicated in the text, but the brand is not indicated. So you need to be determined by the model of the brand and sent to the list with the brands. And also how everything works, but there is a problem, since a brand can have many different models, then duplicate brands are sent to the list, of course.
Who knows how to implement the removal of duplicates in PHP? Tell me an idea or where you can read about it. It seems to be close to the solution, but still does not come out.
Code:
<?php $html = '<div id="one"> <select id="first"> </select> </div> <div id="two"> <select id="second"> </select> </div>'; $dom = new DOMDocument(); $dom->validateOnParse = true; $dom->loadHTML($html); $result_one = get_model(); $string = "audi BMW BMW Ford Ford Ford Ford Ford A6 'A5' mokka mokka."; if($result_one == true){ while($row = mysqli_fetch_array($result_one)){ $pattern = "/\b" . $row["name_model"] . "\b/i"; if (preg_match_all($pattern, $string, $matches)){ for ($i=0; $i < count($matches[0]); $i++){ $count = count($matches[0]); $result = $matches[0][$i]; $result_id = $row["brand_id"]; }//echo $count; $item = $dom->getElementById('first'); $opt = $item->appendChild($dom->createElement("option", $result)); $query = "SELECT * "; $query .= "FROM brands "; $query .= "WHERE brand_id = $result_id "; $result_match = mysqli_query($link, $query); $result_two = $result_match; var_dump($result_two); if($result_two == true) { while($row = mysqli_fetch_array($result_two)){ $res = $row["brand_name"]; $item_2 = $dom->getElementById('second'); $opt = $item_2->appendChild($dom->createElement("option", $res)); } } } } } echo $dom->saveHTML(); ?>
$string = implode(' ', array_unique(explode(' ', $string)));- teran