Delete repetitions within the While

4

I have a search that takes the 3 most relevant results in my DB, and then I separate the categories of those 3 results into an array within a While, so it looks something like:

while($x = $x->fetch()){
   $array = explode(',', $x["categoria"]));
   foreach($categoria as $array){
      $->busca no banco de dados cada categoria
      $->while convertendo e retornando os dados relacionados
   }
}

And within the foreach I want to do the search for the results related to the category of the array in question, however is that when a result fits in more than one category it comes duplicated in the list, my doubts are: How can I delete these duplications? Will it be heavy 3 repetition loops one inside the other?

    
asked by anonymous 11.10.2016 / 19:31

1 answer

1

Hello. You can resolve directly in your SQL query by adding a GROUP BY by the element code you are looking for. Much simpler and faster.

    
11.10.2016 / 22:02