filter query with repeated values only show 1

3

Good morning

I have this query

$eventos_history_query = tep_db_query("select * from " .
 TABLE_HISTORIAL . " where numero_evento = '" .
 $customers['numero_evento'] . "' order by eventos");

 while ($eventos_history = tep_db_fetch_array($eventos_history_query))
 {

in a TABLE_HISTORIAL and there are repeated values in the notes table,

In this example we see that note1 is repeated 3 times:

I just want to show the first note1 as long as it is different from the other examples:

desired result:

How do I perform the query so that note1 of event2 and event3 disappear since it is repeated in event1? only at the inquiry level on the screen

    
asked by Ivan Diaz Perez 04.10.2018 в 11:48
source

1 answer

2

When you scroll through the results, you store the note in a variable and sample it only when it is different from the previous one.

$lastnota = "";
while ($eventos_history = tep_db_fetch_array($eventos_history_query)) {
   //comprobamos si la nota se repite
   if ($lastnota != "" && $lastnota==$eventos_history->nota) {
     $nota = "";
   } else {
     $nota = $eventos_history->nota;
   }
   //imprimes tu resultado - aplica al formato que tengas para mostrarlo
   echo $eventos_history->evento." - ".$nota;
   //actualizamos la variables que alamacena la última nota
   $lastnota =  $eventos_history->nota;
}
    
answered by 04.10.2018 в 13:06