How to do a 'select multiple' start with the first option already checked PHP Mysql

0

Here's my component:

       $query_menu = mysql_query("SELECT 
       rm_id     AS FUNCAO,
       rm_desc   AS DESCRICAO,
       rm_obs    AS OBSERVACAO,
       rm_status AS STATUS 
            FROM radios_menu 
                 WHERE rm_status='0'");

echo"<div class='form-group'>";
  echo"<div class='col-lg-12'>";
    echo"<select multiple='' id='v_desc' name='v_desc' class='form-control'>";
while ($row = mysql_fetch_array($query_menu)){
         $v_funcao    = $row["FUNCAO"];
         $v_desc      = $row["DESCRICAO"];
         $v_obs       = $row["OBSERVACAO"];
         $v_status    = $row["STATUS"];
    echo"<option value='$v_funcao'>$v_desc</option>"; 
         }
    echo"</select>";
  echo"</div>";
echo"</div>";  

With the help of @caiafafardo it worked, but in stylization there was only one thing that I would like to change:  My chosen item is blue:   Plusthe@caiocafardoturnsgray:

How could you make them both blue?  I'm using the bootstrap.

    
asked by anonymous 18.07.2016 / 17:39

1 answer

1

Just check if it's the first pass through WHILE:

$checaPrimeiro = 1;
$checaSeleciona = "";
while ($row = mysql_fetch_array($query_menu)){
    $v_funcao    = $row["FUNCAO"];
    $v_desc      = $row["DESCRICAO"];
    $v_obs       = $row["OBSERVACAO"];
    $v_status    = $row["STATUS"];
    //
    if($checaPrimeiro == 1){
        $checaSeleciona = "selected";
    }else{
        $checaSeleciona = "";
    }
    echo "<option value='$v_funcao' $checaSeleciona>$v_desc</option>"; 
    $checaPrimeiro++;
}
    
18.07.2016 / 18:08