Types of repeated filter records

Asked

Viewed 22 times

0

I have a form with a service search filter that takes the options from a column of my database table. The problem is that more than one person provides the same service, so more has more than one record with the same service, which makes the filter have several equal options.

This is my service filter:

<?php 
    require 'conexao.php';
    $queryServicos = mysqli_query ($link, "SELECT servico FROM teste ORDER BY servico"); 
    $id           = $_POST["id"];
    $serv       = $_POST["servico"];

?>
        <div class="container">
            <table class="table table-bordered">
                <form action="teste-busca.php" method="POST">
                    <div class="form-group col-md-3">
                        <div class="input-group">
                          <span class="input-group-addon">Serviço:</i></span>
                          <select name="servico" id="servico" class="form-control">
                            <option>Selecione...</option>
                            <!-- PEGA OS SERVIÇOS DO BANCO DE DADOS E COLOCA NO OPTION -->
                                <?php while($serv = mysqli_fetch_array($queryServicos)) { ?> 
                                <option value="<?php echo $serv['servico']; ?>"><?php echo $serv['servico']; ?></option>
                                <?php } ?>
                             -->
                          </select>
                        </div>
                    </div>
                </form>
            </table>
        </div>

How do I show up only one service each?

1 answer

1


In the database search, you can use a DISTINCT to return different values.

Example:

  "SELECT DISTINCT servico FROM teste ORDER BY servico"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.