Place alphabetical order increasing the description, when the result comes from a search through numerical field

Asked

Viewed 48 times

0

I now have a question, how to put the relationship of employees of a certain function code in ascending alphabetical order.

I’ll put the code down:

                       <table align="center">
                            <tr>
                                <td id="centro">Selecione Gerente</td>
                            </tr>
                            <tr>
                                <td id="centro">
                                    <select name="txtgerente" id="txtgerente" >
                                        <?php
                                            $query_gerente = "SELECT * FROM colaborador WHERE colab_funcao in($cod_ger,$cod_gerjr) ORDER BY CAST(colab_nome_venda AS UNSIGNED) ASC";
                                            $result_gerente = mysqli_query($con, $query_gerente) or die(mysqli_error());
                                            while ($row_gerente = mysqli_fetch_array($result_gerente)) {
                                                echo("<option value='".$row_gerente['colab_id']."'>".$row_gerente['colab_nome_venda']."</option>");
                                            }
                                        ?>
                                    </select>
                                </td>
                            </tr>
                        </table>

The colab_funcao field is varchar(3). In it is the code of the official’s function.

What I want is for the list of the names of the employees who have the given function but who are in alphabetical order.

Once again, thank you all for your attention and help.

  • From what I could understand: SELECT * FROM colaborador WHERE colab_funcao in($cod_ger,$cod_gerjr) ORDER BY colab_funcao ASC, colab_nome_venda ASC;.

  • Didn’t work, keeps showing disorderly. Thanks for the help...

  • What field contains the name of the employee?

  • colab_nome_venda

  • I did. A very simple thing and I couldn’t see. It looks like this: $query_manager = "SELECT * FROM collaborator WHERE colab_funcao in($cod_ger,$cod_gerjr) ORDER BY colab_nome_venda ASC";

  • All right you managed to meet your need, but note that in your question you say: "how to put the employee list of a certain function code in ascending alphabetical order" and not just all employees in ascending alphabetical order.

  • There were all employees in ascending alphabetical order. I had to first select employees who were from $cod_ger and $cod_gerjr functions. And after this selection, put those selected in ascending alphabetical order.

Show 2 more comments

2 answers

0

RESOLVED

Stayed like this:

$query_gerente = "SELECT * FROM colaborador WHERE colab_funcao in($cod_ger,$cod_gerjr) ORDER BY colab_nome_venda

So simple, and I complicate. Thank you all once again for your attention and help...

0

Good afternoon Clériston Melo ! Try changing your select to see if it works, try this select below:

SELECT * FROM collaborator WHERE colab_funcao in($cod_ger,$cod_gerjr) ORDER BY colab_nome_venda DESC

  • Opa William, thanks for the help, but it didn’t work, continues to show disorderly. Actually shows in ascending numerical order(by employee code).

Browser other questions tagged

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