Sort data in a selected PHP

0

I have a problem with a list in php . It turns out that when I do the SELECT in MySQL I print the list as is, but when I call that SELECT to put it in a list I bring it ordered alphabetically.

That's the order in MySQL and it's how I want it to be:

  • Córdoba
  • Landeta
  • Las Varillas
  • etc ...

And that's how the list comes out in php :

This is the part of the code where the list is created in php ( $res_emp is the SELECT of MySQL which is working well and ready in the first image):

    $res_emp = $this->link_db_cli->query ( $sql_emp );

    //echo $res_emp;die();
    while ( $row_emp = $res_emp->fetch_array ( MYSQLI_ASSOC ) ) {
        $destino [] = $row_emp;         
    }

    $this->link_db_cli->close();
    function cmpl($a, $b) {
        return strcmp ( $a ["geol_nombre"] , $b ["geol_nombre"]);
    }

    usort ( $destino, "cmpl" );

    //$type = "<option>Seleccionar...</option>";
    foreach ( $destino as $reg ) {
        $idl = $_POST [id] . "=" . $reg [geol_id];
        $type .= "<option value='$idl'>" . $reg [geol_nombre] . "</option>";
    }

    return $type;
}

And this is the part in HTML :

<div>
    <div data-role="fieldcontain" id="paradas" style="display: block;">
        <label for="origen"> Su Ubicación: </label> 
        <select name="sel_origen" id="origen" data-native-menu="false" onchange="javascript:CheckUbicacion()"></select>
    </div>                          
</div>
    
asked by Luis 23.04.2018 в 18:21
source

1 answer

2

Your problem is in this line:

usort ( $destino, "cmpl" );

You are sorting the array . Just remove that line and it will work as expected.

    
answered by 23.04.2018 / 18:27
source