Select not to duplicate information

Asked

Viewed 28 times

0

I have a SELECT and what I want is that if there are two OPTION with the same value it only shows one.

As shown in the example below I have 2 Options with Micosoft and I just want it to show me a single Option with Microsoft since I am listing this information from a database

inserir a descrição da imagem aqui

<select class="form-control" id="inserir_fabricante2">
    <option value="" ></option>
        <?php
            $query_d = "SELECT * FROM reparacao ORDER BY fabricante ASC";
            $pv_d = (mysql_query($query_d));
                 while ($row_d = mysql_fetch_array($pv_d)){ ?>
                    <option value="<?php echo $row_d['fabricante']; ?>" ><?php echo  $row_d['fabricante']; ?></option>
                  <?php }   ?>
</select>

1 answer

2


In this case, you can use SELECT DISTINCT, for example:

<select class="form-control" id="inserir_fabricante2">
<option value="" ></option>
    <?php
        $query_d = "SELECT DISTINCT fabricante FROM reparacao ORDER BY fabricante ASC";
        $pv_d = (mysql_query($query_d));
             while ($row_d = mysql_fetch_array($pv_d)){ ?>
                <option value="<?php echo $row_d['fabricante']; ?>" ><?php 
        echo  $row_d['fabricante']; ?></option>
              <?php }   ?>
</select>

To learn more on SELECT DISTINCT.

  • Thanks for the help !!

  • Ooh, mistake my kkkkkkkkkk

  • No Matter Voce guided my mind to the ahah reply Thank you!!

Browser other questions tagged

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