Do not repeat data returned Mysqli [duplicate]

0

I have this code that brings me the months registered in the bank. More like it has several lines, I want to return only once each value.

// Fazendo a conexão
    $conexao  = mysqli_connect($this->dbservidor,$this->dbusuario,$this->dbsenha) or die (mysqli_connect_error($conexao));
    $select   = mysqli_select_db($conexao,$this->dbnome) or die (mysqli_connect_error($select));    
    $query    = mysqli_query($conexao, " SELECT mes FROM programacaoclientes WHERE idCliente = '$idCliente' ");
    $array    = mysqli_fetch_array($query);
    $nums     = mysqli_num_rows($query);

//
    if ( $nums > 0 )
    {   
        // percorrendo
            do
            {   
                // pegando as datas
                    $mes = $array['mes'];

                //
                    echo "<p> <a href='a.php'>$mes</a> </p>";

            }while( $array = mysqli_fetch_array($query) );

    }

Sáida:
  Julho
  Julho
  Julho
  Agosto
  Agosto

I wanted to return only once, without repeating ... What methodology should I use?

    
asked by anonymous 29.06.2017 / 20:23

1 answer

1

Just put GROUP BY in your SELECT :

// Fazendo a conexão
    $conexao  = mysqli_connect($this->dbservidor,$this->dbusuario,$this->dbsenha) or die (mysqli_connect_error($conexao));
    $select   = mysqli_select_db($conexao,$this->dbnome) or die (mysqli_connect_error($select));    
    $query    = mysqli_query($conexao, " SELECT mes FROM programacaoclientes WHERE idCliente = '$idCliente' GROUP BY mes");
    $array    = mysqli_fetch_array($query);
    $nums     = mysqli_num_rows($query);

//
    if ( $nums > 0 )
    {   
        // percorrendo
            do
            {   
                // pegando as datas
                    $mes = $array['mes'];

                //
                    echo "<p> <a href='a.php'>$mes</a> </p>";

            }while( $array = mysqli_fetch_array($query) );

    }
    
29.06.2017 / 20:25