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
  • You would write a specific task, what is at the input, and what is needed at the output. If you need to remove duplicates from a string, then ask precisely this, do not write about how your search works, etc. irrelevant - teran
  • At the input line, where there are 4 models, by search, they are and displayed in the list. I need to put brands of these models from the base of the found models. And the principle goes on and inserts in another list. But at the exit we have A6, A5, mokka, mokka. At the exit issues Audi, Audi, Opel. I need Audi to be once. I already played with conversion. The problem is that after the search, each match throws in a separate array. If you convert, the lines will be as three lines. If we extract the indices of brands that are substituted in the new query, to determine the brands, there will be values ​​of 1, 1, 6. - Sergey Korol
  • Repetitions are at the stage of comparison, I will dig there, I can find what is wrong there. For the data for the second request is formed there. I will go speculate, I can find a solution how else to display the data. - Sergey Korol

0